• 🏆 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!

GUI Timers / Does Call Removetimer(udg_var) Delete the Variable?

Status
Not open for further replies.
Level 18
Joined
Mar 16, 2008
Messages
721
I can't find an exact answer to this anywhere.

If I want to stop a timer and re-set the time on it, will pausing and starting the time be sufficient? or should I call removetimer(udg_var). or will call removetimer permanently delete the gui variable?

Does my question make sense? Thanks for reading.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,579
What MyPad said. And if you're working in GUI then you shouldn't be Removing timers (unless the timer was created locally through custom script). Also, the only time you need to Pause a timer is when you want to stop a Repeating timer. You can then Resume it normally OR Start it again if you want to restart it.

Lastly, there's no such thing as "deleting a variable". You're always deleting the object being tracked by the variable.

It makes more sense once you see the code behind these things.
For example let's say we create a timer variable called MyTimer in GUI. Here's what happens:
vJASS:
udg_MyTimer = CreateTimer()
You're actually creating two things at once. 1) The Timer variable which is what's called a pointer. It simply acts as a reference. 2) The actual Timer object which is created through the CreateTimer() function. This object is really what's important, it is what you Start/Pause/Resume and will contain all of the information/mechanics that a Timer needs. GUI handles this automatically for you, so you don't have to worry about Creating the timer object, it's done already.

In Jass, you need to manually create the timer objects yourself.
Here's an example of creating multiple local timers and timer objects in Jass:
vJASS:
local timer t1 = CreateTimer()
local timer t2 = CreateTimer()
local timer t3 = CreateTimer()

So we just created 3 local timers and given each one it's own timer object, however, none of these timer objects are doing anything yet. That's because we need to tell them what to do using the TimerStart() function:
vJASS:
local timer t1 = CreateTimer()
local timer t2 = CreateTimer()
local timer t3 = CreateTimer()

// There are the parameters you must fill out: TimerStart(whichTimer, timeout, periodic, callback)
call TimerStart(t1, 1.50, true, SomeFunctionThatRunsWhenTheTimerExpires)
So here we told t1 (the first timer we created) to Start it's timer object, and we set it as Repeating (true) and to run every 1.50 seconds. Whenever it expires it will run the SomeFunctionThatRunsWhenTheTimerExpires function (that was a mouthful). That's a function that you would create yourself. However, in GUI, it would be whatever Trigger uses the Event "Your Timer expires".
 
Last edited:
Status
Not open for further replies.
Top