• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[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