- Joined
- Jul 10, 2007
- Messages
- 6,306
GroupEnum(group) //null filter
loop
set unit = FirstOfGroup(group)
exitwhen null == unit
call GroupRemoveUnit(unit)
endloop
Huh? Never had this problem when I used FirstOfGroup loops.I can tell you by experience that this kind of loop has a serious "bug" (because how groups are internally handled).
Make sure there are several times the same unit rawcode (or something like that) in your group.
Now use your loop, it will never end as FirstOfGroup will sooner or later always return the same unit.
globals
group Group = CreateGroup()
endglobals
//===========================================================================
function F takes nothing returns nothing
local unit u = FirstOfGroup(Group)
call BJDebugMsg("run")
loop
exitwhen u == null
call BJDebugMsg(I2S(GetHandleId(u)))
call GroupRemoveUnit(Group,u)
set u = FirstOfGroup(Group)
endloop
set u = null
endfunction
function InitTrig_Test takes nothing returns nothing
call GroupAddUnit(Group,CreateUnit(Player(0),'hpea',0,0,0))
call GroupAddUnit(Group,CreateUnit(Player(0),'hfoo',0,0,0))
call GroupAddUnit(Group,CreateUnit(Player(0),'Hpal',0,0,0))
call TimerStart(CreateTimer(),1,false,function F)
call GroupEnumUnitsInRect(Group,GetWorldBounds(),null)
//call RemoveUnit(FirstOfGroup(Group))
endfunction
globals
group Group = CreateGroup()
endglobals
//===========================================================================
function F takes nothing returns nothing
local unit first = FirstOfGroup(Group)
local unit u = first
if first == null then
return
endif
loop
call BJDebugMsg(I2S(GetHandleId(u)))
call GroupRemoveUnit(Group,u)
call GroupAddUnit(Group,u)
set u = FirstOfGroup(Group)
exitwhen u == first
endloop
set u = null
set first = null
endfunction
function InitTrig_Test takes nothing returns nothing
call GroupAddUnit(Group,CreateUnit(Player(0),'hpea',0,0,0))
call GroupAddUnit(Group,CreateUnit(Player(0),'hfoo',0,0,0))
//call GroupAddUnit(Group,CreateUnit(Player(0),'hpea',0,0,0))
call TimerStart(CreateTimer(),0,false,function F)
call GroupEnumUnitsInRect(Group,GetWorldBounds(),null)
endfunction
But when an unit is removed of the game it isn't removed of the group by itself, and then FirstOfGroup returns null with this removed unit.