• 🏆 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!

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,198
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