Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Fri 03/12/2004 19:31:58

Title: tracking the passage of time in the game, and causing events to occur.
Post by: on Fri 03/12/2004 19:31:58
How to allow time to go by in a game and then cause a function or event to occur after that time is elapsed? I need this to be NON-BLOCKING. Wait functions are blocking, so I can't use them. I tried the SetTimer function, in combination with if (IsTimerExpired (1) ==1){},
but I didn't get it working. Maybe I am not doing it correctly. Can anybody help? Is there another way of allowing time to go by in the game in a NON-BLOCKING way and track that passage of time, and cause events to occur at specific times? Can you be specific in your response? Thank you.
Title: Re: tracking the passage of time in the game, and causing events to occur.
Post by: Ishmael on Fri 03/12/2004 21:51:58
Look for Time function in the holy Manual. I believe the function is called GetTime. But it requires some knowledge of the scripting engine in AGS to get it working perfectly, I reckon.

If you post the code you've used with timers so we can see what's wrong?
Title: Re: tracking the passage of time in the game, and causing events to occur.
Post by: TheJBurger on Sat 04/12/2004 01:45:37
Here's a way to cause timed events to work (I'm sure there are many ways and this is one that I use).

In your repeadetely execute room script add a section like this:

timer++; // continually add time.

if (timer == 40) { // 40 is = 1 real time second, so after 1 second
  MoveCharacter(EGO, 123, 123); // move ego somewhere after 1 second.
  }
if (timer == 120) { // After 2 more seconds...
  AnimateCharacter(EGO, 1, 2, 3); // make EGO do a dance
  }
if (timer == 200) { // After 2 more seconds... or a total of 5 seconds since the start
  NewRoomNPC(BAD, 5, 123, 123);
  }
-----

Then add a line at the top of your room script defining the variable by doing this:
-----
int timer=0; // Define the variable.
-----

So esentially you can change the script's "if (timer == 120)" to any number (just remember 40=1 second and 80=2 seconds etc.), it just depends how much time you want to elapse before the next command. You can also change all what happens in that section to whatever you want.

There are other ways to cause these time events as you said with SetTimer and such, but this might be easier if you want multiple events to happen in one timer.