HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Best method for iterating through group?

11-19-2005, 06:23 PM#1
LegolasArcher
GUI uses ForGroup (Well actually the ForGroupBJ wrapper for it), but this seems very ineffective in JASS. All locals are lost, and I don't even see a method to get around this using Local Handle Variables (What would you attach them to?). After pondering it for a while, this is the only thing I could think of:

Collapse JASS:
local group SomeGroup = CreateGroup()
local unit CurUnit
// Add units to the unit group.
loop
    exitwhen CountUnitsInGroup(SomeGroup) == 0
    set CurUnit = FirstOfGroup(SomeGroup)
    // Do whatever actions on CurUnit.
    call GroupRemoveUnit(SomeGroup, CurUnit)
    set CurUnit = null
endloop
call DestroyGroup(SomeGroup)
set SomeGroup = null

I just coded that as an example, so I'm sure I made a typo somewhere in it. I was just curious if there was a more effecient way of iterating through all the units in a group, since this seems like more of a hack-ish method of doing it than the Right Wayâ„¢.
11-20-2005, 01:36 AM#2
EdwardSwolenToe
Thats the way i made my ForGroup simulator. Although a better way of checking the group would be that FirstOfGroup == null. Apparently its faster than checking units in the group.
11-20-2005, 03:05 AM#3
LegolasArcher
Thanks for the info. I just found it strange that the only effecient way to loop through a group was a sorta hack-ish combination of removing units from it .