• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Group Iterations

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I need to move this function inside my struct, so I can use other variables after the ReplaceUnit function. I suppose I could pass the instance through a static integer in the struct. And have a static method as a ForLoop.


JASS:
private function ReplaceBarrack_T1 takes nothing returns nothing
        local unit u = GetEnumUnit()
        if GetUnitTypeId(u) == BARRACKS_T1 then
            call ReplaceUnit(u, BARRACKS_T2) 
    endfunction

Here is the struct:
JASS:
method upgrade takes nothing returns nothing 
            set .tier = .tier + 1 
            if .tier == 2 then
                set .radius = CITY_BR_T2
                call .replace(CITY_T2)
                call .addBuildingCountTot(BT.getBuildingIndexByType(CITY_T2), 1)
                call SetUnitAbilityLevel(menu.u, MENU_CHANGER, 2)
                call ForGroup(.g, function ReplaceBarrack_T1)

// ...
 
Last edited:
Level 12
Joined
Feb 22, 2010
Messages
1,115
1) Easiest way is using globals to pass your data.

2) If you really want to insist, you need an empty temporary group, then while doing a FirstofGroup loop transfer units to temporary group, and in the end transfer all units from temporary group to main group.

3) If you insist and don't like option 2, I guess you can do something like this, I am not sure.

JASS:
globals
    private group BACKUP = CreateGroup()
    private group t
endglobals
    
method upgrade takes nothing returns nothing
            local unit temp
            set .tier = .tier + 1
            if .tier == 2 then
                set .radius = CITY_BR_T2
                call .replace(CITY_T2)
                call .addBuildingCountTot(BT.getBuildingIndexByType(CITY_T2), 1)
                call SetUnitAbilityLevel(menu.u, MENU_CHANGER, 2)
                loop
                    set temp = FirstOfGroup(.g)
                    exitwhen temp == null

                    if GetUnitTypeId(temp) == BARRACKS_T1 then
                        call ReplaceUnit(temp, BARRACKS_T2) 
                    endif


                    call GroupRemoveUnit(.g, temp)
                    call GroupAddUnit(BACKUP, temp)
                    endloop
                set t = BACKUP
                set BACKUP = .g
                set .g = t

I think it is called group swapping or something
http://www.hiveworkshop.com/forums/2458284-post55.html
 
Status
Not open for further replies.
Top