• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Group Arrays

Status
Not open for further replies.
Level 12
Joined
May 22, 2015
Messages
1,051
Group arrays are fine, just note you will have to create the groups when units use them and that you need to make sure you don't create them more than once. I assume you are using unit indexing. It is also possible with hashtables.
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
i use a unit indexer. i just thought about 2 options:
option 1: having an array of unit groups
option 2: have 1 unit group and save the caster into a variable with the custom value of each target and then loop through the whole group and check each unit

Yep :) as long as you put them seperatly.
If multiple groups are really needed, so not only needed as temporary group, then it's fully okay. :)
okay thanks ;)
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
Ok, i have a new problem :D
if i loop through the group and check for the units attached to the caster, i cannot do it this way:
JASS:
        loop
            set FoG = FirstOfGroup(g)
            exitwhen FoG == null
            call GroupRemoveUnit(g, FoG)
        endloop
because i dont want to remove units from the group that are not attached to the current caster. The loop would be infinite then. I thought about adding the "not fitting" units to a temp group and readd them to the main group after the loop, but that's probably not the best way :D
Is there another way to loop through a group?
 
Level 7
Joined
Oct 19, 2015
Messages
286
A linked list might be more appropriate than a group for what you're trying to do (looping through without emptying it with acces to local variables). It would however be more work to code, unless you are using vJass.
 
Level 12
Joined
May 22, 2015
Messages
1,051
You can also add those units to a separate group (typically referred to as a "swap" group) and swap the groups after the loop.

JASS:
        loop
            set FoG = FirstOfGroup(g)
            exitwhen FoG == null
            call GroupRemoveUnit(g, FoG)
            call GroupAddUnit(g2, FoG)
        endloop

        set gTemp = g
        set g = g2
        set g2 = gTemp
 
Status
Not open for further replies.
Top