Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Cine Beast on Thu 25/08/2011 03:08:59

Title: Trouble with timers.
Post by: Cine Beast on Thu 25/08/2011 03:08:59
Yo, Cine Beast here. I'm nearly finished with my first game, and have encountered a problem that may or may not be a real problem (if it isn't, that's disheartening).

I have a room where four timers are in use. In the load of the room, timer 1 starts and lasts for 2 seconds. After that, in the Repeatedly Executing, timer 2 goes for 2 seconds, then 3, then 4. No problems.

However, at the timeout of 4, I want timer 1 to start (and have the cycle repeat endlessly). It does not.

I'm wondering if this is a standard thing - will a timer only work once. If it isn't, then I'd love some help. I'm inexperienced here, so if you need me to show my code or something, I'll need a hand with that, too.

Thanks in advance.
Title: Re: Trouble with timers.
Post by: Baron on Thu 25/08/2011 03:46:08
There is no limit to the number of times you can reuse or restart timers.  The source of your woes is probably the repeatedly_execute script that should start timer 1 after timer 4 expires.  Just like how you (presumably) started timers 2 through 4, it should look something like:


if (IsTimerExpired () ==4) {
     SetTimer (1, 80);
     //other code, etc.
     }
Title: Re: Trouble with timers.
Post by: monkey0506 on Thu 25/08/2011 04:09:58
IsTimerExpired takes the timer ID as its sole parameter and returns zero (false) or one (true).
So the code should look more like:

function repeatedly_execute()
{
 if (IsTimerExpired(4)) // or IsTimerExpired(4) == 1 or IsTimerExpired(4) == true, they're all the same
 {
   SetTimer(1, 80);
 }
}


@Cine Beast: Any time you have an issue like this, please make sure to post your code. This definitely sounds like a scripting error (as opposed to a bug in the engine), but we'd need to see the code to verify where exactly the problem is at.
Title: Re: Trouble with timers.
Post by: Cine Beast on Thu 25/08/2011 16:13:10
Okay, I rechecked my code, and found one of the stupidest, most easy-to-fix mistakes I've ever made.  :-[
I fixed the error, and now the timers work perfectly.

Thanks for the help, and sorry for the trouble.