1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[vJASS] Replacing TriggerSleepAction with a timer

Discussion in 'Triggers & Scripts' started by DaneTheBeast, Dec 21, 2017.

  1. DaneTheBeast

    DaneTheBeast

    Joined:
    Dec 11, 2014
    Messages:
    608
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Code (vJASS):
    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...?

    What I tried
    Code (vJASS):

    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
     
     
  2. Jampion

    Jampion

    JASS Reviewer

    Joined:
    Mar 25, 2016
    Messages:
    1,287
    Resources:
    0
    Resources:
    0
    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?
     
  3. DaneTheBeast

    DaneTheBeast

    Joined:
    Dec 11, 2014
    Messages:
    608
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I missed the fact that it's sending a local variable, oops. There's no real reason why I'm avoiding them except that I haven't used 'em before, but I shall now.
    Thank you.
     
  4. mori

    mori

    Joined:
    Jun 13, 2016
    Messages:
    465
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    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:
    Code (vJASS):

    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