Author Topic: Set Timer not working with values above 1?  (Read 238 times)

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Set Timer not working with values above 1?
« on: 31 May 2018, 19:32 »
Hello!

In after_fadein I have:

Code: Adventure Game Studio
  1. SetTimer (1, 1);

Which successfully triggers this:

Code: Adventure Game Studio
  1. function repeatedly_execute_always()
  2. {
  3.   if (IsTimerExpired(1) == true){
  4.     //my code here
  5.   }
  6. }

BUT if I change the timeout value to anything other than 1, it doesn't trigger. E.g.

Code: Adventure Game Studio
  1. SetTimer (1, 2); //Does nothing!

I've never had any trouble with timers before, so I feel like I must be making a stupid error. Please help!

EDIT: Some timer numbers seem to work, like 18. So I feel like there must be a clash with a module (like Tween) but I can't find it.
« Last Edit: 31 May 2018, 21:09 by Ali »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #1 on: 31 May 2018, 21:09 »
AGS timers are somewhat a pain to use, do you have (or can you place) a display in your code to make sure the code is not running?

1 and 2 are basically the exact same time... since it's not 1second, but once every time the game runs a loop (and AGS defaults at 40FPS, unless you have changed it 1 equals 1/40th of a second, and 2 is 2/40th...)

IMHO it's better to create your own timer, than using the built in.

But maybe someone with more knowledge will give you a better answer...

EDIT: Since you talk about the Tween module, I seem to remember is has SetTimerInSeconds (or something close to that), use that one maybe if you going for seconds and not game loops? ;)
« Last Edit: 31 May 2018, 21:13 by Cassiebsg »
There are those who believe that life here began out there...

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #2 on: 31 May 2018, 21:16 »
I'm using QuitGame(1); as a clear cut way of finding out if it runs. As I added above, some timer numbers seem to work, like 18.

I feel like there must be a clash with a module (like Tween). Tween has two functions that set timers, but as far as I can tell they are never called anywhere in the script. Nor is Timer 1 set anywhere else.

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #3 on: 31 May 2018, 21:21 »
Well, you could try and set another number for the timer, just to rule that variable out of the way.

also, and because if I don't someone will: What version of AGS are you using and which modules/plugins are you using...
There are those who believe that life here began out there...

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #4 on: 31 May 2018, 22:01 »
I feel a need to clarify just in case, what number are you changing? First parameter is timer ID and second is number of game loops it is supposed to run.
In the script example you are changing timer's delay, but then you talk about timer's clashing with Tween module. So is it timer ID that does not work?

PS. I wrote this Timer module some time ago, it uses custom timer objects stored in a variable instead of built in timers:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=55545.0
« Last Edit: 31 May 2018, 22:05 by Crimson Wizard »

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #5 on: 31 May 2018, 22:22 »
I'm changing the second parameter. It works immediately if set to 1 and seems to do nothing if set to any other number.

I'm using 3.4.0, with lots of modules I wrote (that don't set timer 1) and the Tween Module.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #6 on: 31 May 2018, 22:28 »
Hm, I just tried it, and it works with any number of loops.

Is it possible that the timer checking code may be skipped under some condition? Or the code happening when timer is expired also has some conditions when it won't work?
Do you stop timer anywhere maybe?
« Last Edit: 31 May 2018, 22:32 by Crimson Wizard »

dayowlron

  • been programming computers since 1981
    • I can help with AGS tutoring
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
Re: Set Timer not working with values above 1?
« Reply #7 on: 01 Jun 2018, 00:07 »
I would be curious to know where you call the SetTimer function. If this function is called repeatedly then it will never expire because you keep setting it.
Pro is the opposite of Con
This fact can clearly be seen,
If progress means to move forward
Then what does congress mean?  --Nipsey Russell

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #8 on: 01 Jun 2018, 00:09 »
It's just called from after fade in, so it shouldn't be repeating.

Re: Set Timer not working with values above 1?
« Reply #9 on: 01 Jun 2018, 03:39 »
Use CW Timer module when you need a timer. It's so much better then regular AGS Timer they should just come in every template.

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #10 on: 04 Jun 2018, 01:30 »
I am now using CW's module, and it works. Some of the built-in timer numbers seemed to work and some didn't. It's the first time I've ever found AGS to be inconsistent (without it quickly turning out to be my fault). I'm sure this was my fault somehow, but for the life of me I can't find any other script dealing with the relevant timers.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Set Timer not working with values above 1?
« Reply #11 on: 04 Jun 2018, 09:45 »
I am now using CW's module, and it works. Some of the built-in timer numbers seemed to work and some didn't. It's the first time I've ever found AGS to be inconsistent (without it quickly turning out to be my fault). I'm sure this was my fault somehow, but for the life of me I can't find any other script dealing with the relevant timers.

It's hard to guess without seeing a full code around IsTimerExpired and under it. I may imagine following possibilities -

1) You are doing IsTimerExpired for the same timer more than once in various places in code. According to the manual, as soon as you check it once, the "expired" flag is reset, and second check will never return true.
2) There is more code around IsTimerExpired that prevents it to be called in time.
3) IsTimerExpired worked, but there is a mistake in code under condition that prevents wanted actions.
4) There is a code around SetTimer that prevents it from being called with certain arguments.
5) SetTimer or IsTimerExpired does not work for some reason.
6) repeatedly_execute_always does not get called for some reason.

Without seeing the rest of the code, only suggestion that comes to mind right now, is to write log into file, and record when SetTimer gets called, when repeatedly_execute_always got called (maybe output number of times it got called until timer expired), and immediately when timer expires.