Set Timer not working with values above 1?

Started by Ali, Thu 31/05/2018 19:32:23

Previous topic - Next topic

Ali

Hello!

In after_fadein I have:

Code: ags
SetTimer (1, 1);


Which successfully triggers this:

Code: ags
function repeatedly_execute_always()
{
  if (IsTimerExpired(1) == true){
    //my code here
  }
}


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

Code: ags
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.

Cassiebsg

#1
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? ;)
There are those who believe that life here began out there...

Ali

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

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

#4
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

Ali

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

#6
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?

dayowlron

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                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Ali

It's just called from after fade in, so it shouldn't be repeating.

eri0o

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

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

Quote from: Ali on Mon 04/06/2018 01:30:59
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.

SMF spam blocked by CleanTalk