- Joined
- Oct 12, 2011
- Messages
- 3,449
Hey peeps! I have a lil bit weird problem here.
In short, I have a function that contains pack of actions. But those actions only execute if only the timer (delay timer) remaining time is 0. The timer starts again whenever the actions execute successfully. So the timer acts like a cooldown for the function.
I use TimerUtils. I know TimerUtils doesn't destroy the timer when the timer is released, it's paused instead. So on initialization, whenever I call NewTimer(), logically, I will have to reset the timer's remaining time by calling
I displayed the debug message before and after the timer reset.
And the reset part works okay. Sometimes it prints "was: 0.052" and "now: 0.00". But I also displayed a debug message when the function is called, displaying the remaining time of the cooldown timer. And the weird thing is that it always prints the remaining time before the timer is reset, 0.052.
Does anyone know what's going on here?
EDIT:
SOLVED
I've found that somehow
I.E. a timer is paused when it still has 0.5s remaining time. When the timer is reset (
So to fully reset the remaining time of the timer to zero, all I have to do is to pause the timer right after reset. So the code looks like this:
And yes, now it works okay... finally...
In short, I have a function that contains pack of actions. But those actions only execute if only the timer (delay timer) remaining time is 0. The timer starts again whenever the actions execute successfully. So the timer acts like a cooldown for the function.
I use TimerUtils. I know TimerUtils doesn't destroy the timer when the timer is released, it's paused instead. So on initialization, whenever I call NewTimer(), logically, I will have to reset the timer's remaining time by calling
TimerStart(theTimer, 0, false, null)
, right? Just in case that TimerUtils return me an already-used-timer.I displayed the debug message before and after the timer reset.
JASS:
set timer = NewTimer()
call BJDebugMsg("was: " + R2S(TimerGetRemaining(timer)))
call TimerStart(timer, 0, false, null)
call BJDebugMsg("now: " + R2S(TimerGetRemaining(timer)))
And the reset part works okay. Sometimes it prints "was: 0.052" and "now: 0.00". But I also displayed a debug message when the function is called, displaying the remaining time of the cooldown timer. And the weird thing is that it always prints the remaining time before the timer is reset, 0.052.
Does anyone know what's going on here?
EDIT:
SOLVED
I've found that somehow
PauseTimer
messes up with TimerGetRemaining
, and probably with the other timer getter functions as well. Looks like it freezes the remaining time of a timer at the former value when the timer got paused.I.E. a timer is paused when it still has 0.5s remaining time. When the timer is reset (
TimerStart(timer, 0, false, null)
), the remaining time will be 0 (correct). But when the timer expires, the remaining time will reset to 0.5s, back to the value when the timer was previously paused. This is just speculation btw. I haven't proved it that it really behaves this way.So to fully reset the remaining time of the timer to zero, all I have to do is to pause the timer right after reset. So the code looks like this:
JASS:
set timer = NewTimer()
call TimerStart(timer, 0, false, null)
call PauseTimer(timer)
And yes, now it works okay... finally...
Last edited: