| 08-21-2008, 11:18 PM | #1 |
I have this: 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 |
Replace this: set temp = barracks
With this: call GroupAddGroup(barracks, temp) |
| 08-22-2008, 12:31 AM | #3 | |
Quote:
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 |
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 |
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 |
| 08-22-2008, 09:45 AM | #6 | |
Quote:
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 |
