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

[vJASS] Replacing TriggerSleepAction with a timer

Status
Not open for further replies.
Level 12
Joined
Dec 11, 2014
Messages
662
JASS:
function Actions takes nothing returns nothing
    local unit Attacker = GetAttacker()
    local integer Loop = 2
    //SOME CODE. . .

    loop
        exitwhen Loop > 16
        if ((IsUnitInGroup(Attacker, udg_ugCreepGroup_Array[Loop]) == true)) then
            call TriggerSleepAction(0.10)
            call IssuePointOrderLocBJ(Attacker, "move", udg_ptRegions_Array[Loop])
        endif
        set Loop = Loop + 1
    endloop
Is there a way to replace the call TriggerSleepAction(0.10) with TimerStart without implementing a hashtable?
I've tried using call TimerStart(t, 5.00, false, IssuePointOrderLocBJ(Attacker, "move", udg_ptRegions_Array[Loop]) instead of it but says the boolean value is invalid...?

JASS:
function Actions takes nothing returns nothing
    local unit Attacker = GetAttacker()
    local integer Loop = 2
    local timer Time = CreateTimer()
    //SOME CODE. . .

    loop
        exitwhen Loop > 16
        if ((IsUnitInGroup(Attacker, udg_ugCreepGroup_Array[Loop]) == true)) then
            call TimerStart(Time, 0.2, false, IssuePointOrderLocBJ(Attacker, "move", udg_ptRegions_Array[Loop]))
        endif
        set Loop = Loop + 1
    endloop
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
TriggerSleepAction works within one function, so you can use local variables even after the wait.
For timers a new function is started, so locals cannot be used.

So in the end when using timers you either need to store your values in a hashtable or a global variable. If you index timers you can also use arrays or structs (vJASS) instead of a hashtable.
Why would you try to avoid using a hashtable?
 

~El

Level 17
Joined
Jun 13, 2016
Messages
557
Hey, this is a great opportunity to offer you to try Wurst, because what you are trying to do is much more natural and straightforward to do in Wurst.
Like this:
JASS:
package Test
import ClosureTimers

function timers()
    int i = GetRandomInt(10, 1000)
    print("Random int at start " + i.toString())

    doAfter(10, () -> begin
        print("Random int 10 seconds after " + i.toString())
   
        doAfter(10, () -> begin
            print("Random int 20 seconds after " + i.toString())
        end)
    end)

You can go here to find out
 
Status
Not open for further replies.
Top