• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[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:
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
https://www.hiveworkshop.com/forums/2458284-post55.html
 
Status
Not open for further replies.
Back
Top