• 🏆 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] how does unit group store units?

Level 7
Joined
Oct 12, 2020
Messages
82
if i make an unit group an array and store 3 bandits in index 0 and 4 rouge in index 1 and then loop over it , when i check if picked unit at index 0 is dead or not , does it check if all the units in an index are dead? or does it make a sub array?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,558
You aren't checking the (Picked unit) stored at index 0, you're Looping over the Unit Group stored at index 0 and running the Loop - Actions once for each unit contained inside of it. It's an array of Unit Groups, not Units.
  • Set Variable UnitGroup[0] = (Units of type Footman)
  • Set Variable UnitGroup[1] = (Units of type Knight)
  • Unit Group - Pick every unit in UnitGroup[0] and do actions...
    • Loop - Actions
      • // (Picked unit) will be a different Footman each Loop cycle
  • Unit Group - Pick every unit in UnitGroup[1] and do actions...
    • Loop - Actions
      • // (Picked unit) will be a different Knight each Loop cycle
The whole point of Unit Groups and the Pick Every Unit action is to allow the user to repeat an Action or set of Actions for multiple units at once. It frees you from needing to track each unit on an individual basis and helps you avoid repetition. An array of Unit Groups allows you to create multiple Unit Groups and contain them within the same variable. This can be combined with indexing techniques to then link each Unit Group to a specific Player or Unit or whatever you want.

Also, note that Unit Groups from a Unit Group array need to have their Size manually set or need to be initialized with the CreateGroup() function in order to work beyond the [1st] index. This is because a Unit Group variable only creates the actual Unit Group object for the first two [indexes]. I assume Blizzard thought it would be inefficient to fill all [32,768] indexes with Unit Group objects since users often only need a few of them.
 
Last edited:
Top