Author Topic: How to Code Real Time Events Taking Place?  (Read 219 times)

Vverano7

  • Posts: 13
How to Code Real Time Events Taking Place?
« on: 30 Dec 2017, 02:25 »
Hi, I am new to AGS and am creating a game. In my game, I want the player to have a lot of freedom and choice in regard to catching this one thief character. I was kinda reminded of a game like The Last Express, where events will take place real time. I wanted to have something like this in my game. For example, the thief would be at Scene 1 in 1 minute, Scene 5 at minute 7, etc... Would it be possible to code this? I want the player to have to find the thief based off what point the thief is up to. For example, if the player were to merely follow the thief, he would continuously walk through around 10 scenes before completing a game event. How would I code this? (Sorry for the weird wording)

Thank you.

Snarky

  • Global Moderator
  • Posts: 6,706
  • Private Insultant
    • I can help with proof reading
    • I can help with translating
Re: How to Code Real Time Events Taking Place?
« Reply #1 on: 30 Dec 2017, 08:48 »
Keep track of the in-game time using a global variable, which you update in repeatedly_execute(). Base your game logic on the value of this variable.

To keep track of time, use something like this:

Code: Adventure Game Studio
  1. // Global variables:
  2. // int timeCounter
  3. // bool isTimeRunning
  4.  
  5. function repeatedly_execute()
  6. {
  7.   if(isTimeRunning)
  8.     timeCounter++;
  9. }

To make the thief carry out some script at various times, I would use an enum with the times for the different steps, and update his progress in repeatedly_execute():

Code: Adventure Game Studio
  1. enum ThiefAction
  2. {
  3.   // A list of the different things the thief does at what time (in seconds)
  4.   eThiefBeforeBreakIn = 0,
  5.   eThiefEnterHouse = 120,
  6.   eThiefOpenSafe = 150,
  7.   eThiefGetawayGarden = 180,
  8.   eThiefGetawayStreet = 200,
  9.   eThiefHideOut = 240
  10. };
  11.  
  12. ThiefAction currentThiefAction;
  13.  
  14. function repeateadly_execute()
  15. {
  16.   switch(currentThiefAction)
  17.   {
  18.     case eThiefBeforeBreakIn:
  19.       // TODO: Logic for before break-in
  20.       // Switch to next state at the right time
  21.       if(timeCounter * GetGameSpeed() >= eThiefEnterHouse)
  22.       {
  23.         cThief.ChangeRoom(OFFICE);
  24.         currentThiefAction = eThiefEnterHouse;
  25.       }
  26.       break;
  27.     case eThiefEnterHouse:
  28.       if(timeCounter * GetGameSpeed() >= eThiefOpenSafe)
  29.       {
  30.         safeIsOpen = true; // This is some global variable
  31.         currentThiefAction = eThiefOpenSafe;
  32.       }
  33.       break;
  34.     case eThiefOpenSafe:
  35.       if(timeCounter * GetGameSpeed() >= eThiefGetAwayGarden)
  36.       {
  37.         cThief.ChangeRoom(GARDEN);
  38.         currentThiefAction = eThiefGetAwayGarden;
  39.       }
  40.       break;
  41.     // ETC.
  42.   }
  43. }