• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Unit Iteration

Status
Not open for further replies.
Of the many ways to iteration over a set a units, which methods should be used in which situations?

Methods:
  1. ForGroup
  2. FirstOfGroup
  3. GroupEnumUnitsInRect
  4. Or simply looping over an array.
Situations:
  • Iterating over a group of units.
  • Iteration over a temporary group of units.
  • Iterating over a group while already iterating over a group, for both above situations.

Because I doubt that a single method is best for everything.
Which methods count towards the OPLimit, and which ones don't (Actions done to EnumUnit)?
 
When iterating over a group of units where you don't need the group afterward, FirstOfGroup() is usually faster (marginally) and often more convenient (see these benchmarks).

ForGroup() would be used if you need the units/group structure to be maintained.

You iterate through the filter if you need to maintain the group afterward but need to iterate through the units at the time of enumeration (controlling who is added/removed from the group). By this, I just mean that performing the actions you need to do directly in the filter is usually better than:
JASS:
call GroupEnum...(g...Condition(function someFilter))
call ForGroup(g)
In that case it is kind of like merging conditions and actions for a trigger.

ForGroup() starts a separate thread so that is another reason why you may want to use it. FirstOfGroup(), of course, runs on the current thread.
 
Status
Not open for further replies.
Back
Top