• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Timer Remaining Time Problem

Status
Not open for further replies.

Kazeon

Hosted Project: EC
Level 33
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 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:
Level 17
Joined
Apr 27, 2008
Messages
2,455
Your assumption is correct :
http://www.hiveworkshop.com/forums/jass-resources-412/repo-jass-h4xx-222591/

TimerUtils should be edited. Last time i checked more fix were needed.
I was against creating a new timer library, because TU is commonly used, but maybe it's time to do it, because Vexorian is out of the community since a while now.
And TU lacks features imho.

So maybe submit the one lying in the graveyard ?

In my opinion a StartNewTimer function would be good (start a new timer, link an integer).
Most of time when you need a new timer, you start it immediatly anyway and we still can keep NewTimer and NewTimerEx.
 
Your assumption is correct :
http://www.hiveworkshop.com/forums/jass-resources-412/repo-jass-h4xx-222591/

TimerUtils should be edited. Last time i checked more fix were needed.
I was against creating a new timer library, because TU is commonly used, but maybe it's time to do it, because Vexorian is out of the community since a while now.
And TU lacks features imho.

So maybe submit the one lying in the graveyard ?

In my opinion a StartNewTimer function would be good (start a new timer, link an integer).
Most of time when you need a new timer, you start it immediatly anyway and we still can keep NewTimer and NewTimerEx.

by graveyard you mean the one written by Mag? Mag stated that he wrote it because Vex's is not updated, yet he graveyarded it because Vex updated it after a long wait?
 
Status
Not open for further replies.
Top