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

Delayed Trigger in "GUI"

Status
Not open for further replies.
Is there anything wrong with doing:
Caller
  • Custom script: local timer t = CreateTimer()
  • ... The actual stuff
  • Custom script: call TimerStart(t, 0.60, false, function Trig_DelayedGUITriggerName_Actions)
  • Custom script: set t = null
Called after delay
  • DelayedGUITriggerName
    • Events
    • Conditions
    • Actions
      • Custom script: local timer t=GetExpiredTimer()
      • Custom script: call PauseTimer(t)
      • Custom script: call DestroyTimer(t)
      • Custom script: set t=null
      • ...
      • The actual stuff
Is there an advantage to use an indexed array of "temp timers"?
Does this leak?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
Does nulling t in the first trigger work? Aren't you immediately setting the Timer to null?

And the reason to use Indexed Arrays is to store unique data to them so you can reference it later

Like create Timer[1], set TimeUnit[1] = Some unit, then when a Timer expires you get the Index (X), and can now reference TimeUnit[X].

Also, it looks like you're ready to start coding, why not ditch GUI entirely :p (I recommend Lua > Jass)
 
I actually have not tested the above yet, but isn't all "handles" just pointers and nulling pointer does not destroy the underlying timer that is started?

I'm locked in with jass for the current project. It's mostly been laziness and that I have not looked up an environment where I can autocomplete/find native functions. There is a vjass plugin for vscode, but no native support that I've found. Although I have not put that much effort into it yet.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
I actually have not tested the above yet, but isn't all "handles" just pointers and nulling pointer does not destroy the underlying timer that is started?

I'm locked in with jass for the current project. It's mostly been laziness and that I have not looked up an environment where I can autocomplete/find native functions. There is a vjass plugin for vscode, but no native support that I've found. Although I have not put that much effort into it yet.
Yeah, I think you're right. Doesn't look like there's any reason it'd leak.

I think this may be what you're looking for:
vjass support extension for Visual Studio Code
 
Your example should work just fine and there is no mistake or leak in there.

You dont need indexing unless you dont want to attach data to that timer to use in the callback function.
But most often you do. I that case, add a hashtable into the mix and use the handle ID of the timer as the parent key of your table.
Imho thats much easier than having an indexed array of timers as you dont have to worry about the index recycling (handle IDs are always unique per timer).

I do agree with the previous suggestion though:
When you start implementing timers in GUI, you are ready to make the switch to vJASS (or Lua, whatever you prefer).



Here is the basic implementation of a simple timer attachment in vjass for reference.
As you can see its exactly as yours, the only thing different is the usage of hashtables to store data to the timers handle ID.

JASS:
globals
    hashtable hash = InitHashtable()
endglobals

function bar takes nothing returns nothing
    local timer t = GetExpiredTimer()
    //load attached data:
    local integer data = LoadInteger(hash, GetHandleId(t), 0)
    local unit someunit = LoadUnitHandle(hash, GetHandleId(t), 1)

    //This cleans up the table entries used:
    call FlushChildHashtable(hash, GetHandleId(t)
    call DestroyTimer(t)
 
    //null local handles
    set someunit = null
    set t = null
endfunction

function foo takes nothing returns nothing
    local timer t = CreateTimer()
    local integer data = ...
    local unit someunit = ...

    //attach whatever data you need via the Save natives to your hashtable
    call SaveInteger(hash, GetHandleId(t), 0, data)
    call SaveUnitHandle(hash, GetHandleId(t), 1, someunit)
    call TimerStart(t, false, 0.6, function bar)

    //dont forget nulling local handle variables
    set t = null
    set someunit = null
endfunction
 
Last edited:
Status
Not open for further replies.
Top