- Joined
- Oct 11, 2012
- Messages
- 711
Whats the most efficient way to count units in a group? Better way than the following function?
JASS:
CountUnitsInGroup
CountUnitsInGroup
Hm I would only know this
Set Count=0
Pick every unit in UnitGroup:
Set Count = Count +1
But why you dont want to use your function?
Just using 'Count Units in UnitGroup' is best I guess
call GroupEnumUnitsInRange(g,x,y,800.,function groupfilter)
set z=I2R(CountUnitsInGroup(g))
set damm=dam/z
loop
set u=FirstOfGroup(g)
exitwhen u==null
call GroupRemoveUnit(g,u)
call UnitDamageTarget(target,u,damm,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_DEMOLITION,null)
endloop
call DestroyGroup(g)
set g=null
set dam=0
set bj_groupCountUnits = 0
call ForGroup(group, function CountUnitsInGroupEnum)
call BJDebugMsg(I2S(bj_groupCountUnits) + " in group")
CountUnitsInGroup
should be fine as well.I guess, if you use your own (already existing) UnitGroup, it wont leak.
But if you create a new one it will I think,.. like Count all Units in Playable Map area (so you create a new group)
Edit: but I'm not quite sure for that, only my thoughts
You can use the same group for the script above, don't destroy it. I recommend that over creating a new group every time.
He means that he recommends using a Global unit group rather than creating a new unit group every time your function runs.