unitgroup g = UnitGroup(blah blah);
unit fog;
int i;
for (i = 0; UnitGroupUnit(g, i) != null; i += 1){
fog = UnitGroupUnit(g, i);
blah blah
}
or instead of UnitGroupUnit(g, i) != null you can do i <= UnitGroupCount(g, c_unitCountAll) it's the same thing, better yet save the maxUnitIndex to a variable instead of checking it every loop.
Galaxy has a special unit group iterator function (which is what GUI uses). I would advise using that as it is potentially more efficient than looking up units (complexity is implementation dependent and might be O(n)).
I tried so far... local ugroup = nil ugroup = UnitGroup( 0, UnitFilter( 0, 0, 0, 0), 0, 1, 0)
UnitGroupLoopBegin(ugroup)
local count = 0 while (not UnitGroupLoopDone()) do count = count + 1 print("count: " .. tostring(count)) UnitGroupLoopStep()
end UnitGroupLoopDone() UnitGroupClear(ugroup)
but it seems not to work
@gemcollectersummer: Go
Use UnitGroupUnit to get the unit at a specific index and something like UnitGroupSize or something like that to know how many units there are.
If you don't know just do it using the GUI and then look at the code it generates.
Generally i do something
unitgroup g = UnitGroup(blah blah);
unit fog;
int i;
for (i = 0; UnitGroupUnit(g, i) != null; i += 1){
fog = UnitGroupUnit(g, i);
blah blah
}
or instead of UnitGroupUnit(g, i) != null you can do i <= UnitGroupCount(g, c_unitCountAll) it's the same thing, better yet save the maxUnitIndex to a variable instead of checking it every loop.
Galaxy has a special unit group iterator function (which is what GUI uses). I would advise using that as it is potentially more efficient than looking up units (complexity is implementation dependent and might be O(n)).
Yeah just use, "For Each Unit in Unit Group"
It will iterate and set a specified variable to the current unit and then loop to the next one.