• 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] Loop not working?

Status
Not open for further replies.
Level 12
Joined
Dec 10, 2008
Messages
850
Ok, so after learning how to write JASS to work with me, I'm struck with a problem. See, I have this spell that is supposed to create 15 waves of 5 units. It set to use a loop within a loop. The only problem is (dont shoot me for it) I cant get TriggerSleepAction to work effectivly for me, instead it skips it and only loops once. Any help with this?

JASS:
function Trig_Artillery_Actions takes nothing returns nothing
    local location ArtilleryPoint = GetSpellTargetLoc()
    local unit ArtilleryCaster = GetSpellAbilityUnit ()
    local rect ArtilleryRegion = RectFromCenterSizeBJ(ArtilleryPoint, 1000.00, 1000.00)
    local group ArtilleryGroup = GetUnitsInRectAll(ArtilleryRegion)
    local integer ArtilleryLoop1 = 1
    local integer ArtilleryLoop2 = 1
    local location ArtilleryLocU
    local unit ArtilleryUnit
    local unit ArtilleryUnit2
    call GroupRemoveUnit( ArtilleryGroup, ArtilleryCaster )
    loop
        exitwhen ArtilleryLoop1 > 15
        loop
            exitwhen ArtilleryLoop2 == 30
            set ArtilleryLocU = GetRandomLocInRect(ArtilleryRegion)
            call CreateUnitAtLoc(GetTriggerPlayer(), 'h00B', ArtilleryLocU, bj_UNIT_FACING )
            set ArtilleryUnit = GetLastCreatedUnit()
            call CreateUnitAtLoc(GetOwningPlayer(ArtilleryCaster), 'h00F', ArtilleryLocU, bj_UNIT_FACING )
            set ArtilleryUnit2 = GetLastCreatedUnit()
            call SetUnitTimeScale( ArtilleryUnit, 25.00 )
            call SetUnitScalePercent( ArtilleryUnit, 500.00, 500.00, 1000.00 )
            call SetUnitAnimation( ArtilleryUnit, "birth" )
            call SetUnitAnimation( ArtilleryUnit2, "birth" )
            call UnitApplyTimedLife( ArtilleryUnit, 'BTLF', 0.50 )
            call UnitApplyTimedLife(ArtilleryUnit2,'BTLF',0.50)
            call UnitDamagePointLoc( ArtilleryCaster, 0, 500, ArtilleryLocU, 5.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
            call RemoveLocation (ArtilleryLocU)
            set ArtilleryLoop2 = ArtilleryLoop2 + 1
        endloop
        set ArtilleryLoop1 = ArtilleryLoop1 + 1
        call TriggerSleepAction (.27)
    endloop
    call UnitDamagePointLoc( ArtilleryCaster, 0, 1000.00, GetRectCenter(ArtilleryRegion), 300.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    call RemoveRect (ArtilleryRegion)
    call RemoveLocation (ArtilleryPoint)
    call DestroyGroup (ArtilleryGroup)
endfunction
Help is much welcomed (feel free to help with any other kinks in it too!)
And of course +rep to helpers
 
Level 3
Joined
Aug 20, 2008
Messages
54
Yeah, use timers, if you dont know how to, then use:
JASS:
call PolledWait(#.##)
Its a little more accurate than TSA (TriggerSleepAction). TSAs are horrible, they can cause desyncs so you dont ever want to use them. A desync is where a player or players will disconnect because the information in the map on one computer is different than on another computer. Vague explanation, but I hope you understand the point that they are very bad.

However, I would also advise you not to create a unit and set it to a variable after.
Here is the part of your code Im talking about:
JASS:
call CreateUnitAtLoc(GetTriggerPlayer(), 'h00B', ArtilleryLocU, bj_UNIT_FACING )
            set ArtilleryUnit = GetLastCreatedUnit()

Instead you may want to use:
JASS:
set ArtilleryUnit = CreateUnitAtLoc(GetTriggerPlayer(), 'h00B', ArtilleryLocU, bj_UNIT_FACING)
That sums up 2 actions into 1.
Anyway, hope this helped. If you have any questions you can PM me.

EDIT: Dont forget to add leak cleaners before ending the function.
JASS:
    set ArtilleryUnit = null
    set ArtilleryUnit2 = null
    set ArtilleryCaster = null
endfunction
 
Level 12
Joined
Dec 10, 2008
Messages
850
Thanks for the help, but it still wont re-loop it. I'm writing it in JassCraft and moving it into the maps header, could that be the problem?

Edit: Ok, somethings wrong, I've tryed modifiying the script to see if its a problem with my loop method, but it wont even let me test it when I narrow it down to just 1 loop
 
Status
Not open for further replies.
Top