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

[Solved] Loop problem

Status
Not open for further replies.
Level 11
Joined
Sep 14, 2009
Messages
284
In this small section of a trigger I have a loop that never ends and I don't know why. The message in the loop gives 2, 2, 2... and so on and then just stops but the "Loop end" is never displayed.

JASS:
function CombatLostDialogButton01_Actions takes nothing returns nothing
    local group g
    local unit u
    //----------
    set g = GetUnitsInRectAll(udg_CombatRect)
    set u = FirstOfGroup(g)
    call DisplayTextToForce(GetPlayersAll(), "Loop start")
    loop
        exitwhen CountUnitsInGroup(g) == 0
        set u = FirstOfGroup(g)
        call RemoveUnit(u)
        call DisplayTextToForce(GetPlayersAll(), I2S(CountUnitsInGroup(g)))
    endloop
    call DisplayTextToForce(GetPlayersAll(), "Loop end")
    call DestroyGroup(g)
    set g = null
    set u = null
endfunction

EDIT: Solved. Thanks Ceday.
 
Last edited:
Level 12
Joined
Feb 22, 2010
Messages
1,115
You should remove your unit from group before removing it, because if you use FirstOfGroup loops the units that removed from game still counted as in group.

Also you can do this, counting units in group twice is not neccesary.
JASS:
loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call GroupRemoveUnit(g, u)
        call RemoveUnit(u)
        call DisplayTextToForce(GetPlayersAll(), I2S(CountUnitsInGroup(g)))
    endloop
 
Status
Not open for further replies.
Top