• 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.

Avoiding ForGroup

Status
Not open for further replies.
Level 14
Joined
Apr 20, 2009
Messages
1,543
I would like to ask how one would loop through a group while keeping units in the group without having to use ForGroup?
Perhaps something like a swap group, although I'm not really sure how to accomplish that.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
The basic solution is a swap group. As long as you completely iterate the previous group you can add all units from the source group to another group and then at the end of the loop swap the source variable to use the new group. This is useful for performance critical systems that use groups and need to keep their contents.

It is not useable when the source of the group is not explicit such as a function parameter or a group referenced by multiple variables. In such a case the good old approach of ForGroup is probably best since you do not need to concern yourself about what references the group then.

One could technically abstract groups and implement a generic solution. If you make a struct "Group" then you could have multiple references references to a single explicit physical reference of the group so the swap group approach would work in all cases then. The extra abstraction does add overhead which may or may not be worth it.
 
Status
Not open for further replies.
Top