HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How do you loop through a group withing removing the units?

08-21-2008, 11:18 PM#1
The__Prophet
I have this:
Collapse JASS:
    local group temp = CreateGroup()
    local integer i = 0
    set temp = barracks
    call BJDebugMsg("Start Barracks: " +I2S(CountUnitsInGroup(barracks)))
    set u = FirstOfGroup(temp)
    if GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) > 200 then 
        loop
            exitwhen u == null
            set i = 0
            set u = FirstOfGroup(temp)
            call GroupRemoveUnit(temp, u)
            loop
                exitwhen i > 2
                call IssueImmediateOrderById(u, ID1)
                call IssueImmediateOrderById(u, ID2)
                call IssueImmediateOrderById(u, ID1)                
                set i = i + 1
            endloop
        endloop
    endif
    call BJDebugMsg("End Barracks: " +I2S(CountUnitsInGroup(barracks)))    

I set the group to a temp, yet when I remove the unit from the temp group it also removes it from the main group. Why?
08-22-2008, 12:03 AM#2
Anitarf
Replace this: set temp = barracks With this: call GroupAddGroup(barracks, temp)
08-22-2008, 12:31 AM#3
Vexorian
Quote:
I set the group to a temp, yet when I remove the unit from the temp group it also removes it from the main group. Why?

Imagine handle variables as if they were arrows pointing to the actual object, when you assign a variable to another you are just making it point to the same thing the other variable was pointing at.
08-22-2008, 04:21 AM#4
burningice95
What vex said, setting one group = to another doesn't make a copy of that group with the same units, it gives you two variables that refer to the same group.
08-22-2008, 06:10 AM#5
DioD
ForGroup() + set of globals faster and more easy
Code:
                exitwhen i > 2
                call IssueImmediateOrderById(u, ID1)
                call IssueImmediateOrderById(u, ID2)
                call IssueImmediateOrderById(u, ID1)                
                set i = i + 1
only last order for unit in thread will pass.
08-22-2008, 09:45 AM#6
Themerion
Quote:
ForGroup() + set of globals faster and more easy
Collapse JASS:
function Enum takes nothing returns nothing
  local integer i=0
  exitwhen i > 2
    call IssueImmediateOrderById(u, ID1)
    call IssueImmediateOrderById(u, ID2)
    call IssueImmediateOrderById(u, ID1)                
  set i = i + 1
endfunction

//....

if GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) > 200 then 
    // if you would need some data to be passed to the ForGroup...
    // set tempVaraible = whatever
    call ForGroup(barracks, function Enum)
endif