• 🏆 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] How can I set a loop to exit when a unit moves?

Status
Not open for further replies.
Level 4
Joined
Jul 1, 2008
Messages
49
How can I set a loop to exit when a unit moves?

JASS:
globals
boolean stop = true
endglobals
//===========================================================================
// loop function when this function is called it will start the loop and when a unit moves it will stop
function loop_function takes nothing returns nothing
loop
exitwhen stop == false
    
endloop
set stop = true //reset the stop variable so it can be used again
endfunction
//===========================================================================
// trigger Actions and Conditions
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    set stop = false
endfunction
function Trig_Untitled_Trigger_001_Conditions takes nothing returns boolean
    return GetIssuedOrderId() == OrderId("move")
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_001, Condition( function Trig_Untitled_Trigger_001_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction

this is a simple example i hope it help if it what you want
 
JASS:
function LoopFunction takes unit u returns nothing
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local real newX
        local real newY
        loop
            set newX = GetUnitX( u )
            set newY = GetUnitY( u )
            exitwhen (newX != x) or (newY != y)
            //Do your things here
            call TriggerSleepAction( 0.1 )
        endloop
endfunction

I don't know which way is better but this is (probably) the easiest way.
 
Status
Not open for further replies.
Top