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

Fault in For Each Integer loop indexing

Status
Not open for further replies.
Level 7
Joined
May 15, 2009
Messages
192
Hello Hive, and welcome to another session of "Battlehound's a noob"

In short, I tried to make a 'smart' system to add several indexed units into different Unit Group Arrays.
I need 14 units to be divided into 7 different groups (sometimes these groups consist of just one individual).
The trigger should be fairly self-explanatory, so I won't drown it (but ask questions if anything is unclear!).

The first group of 3 indexed units gets added to a group well enough, but it doesn't work for the remaining 6 groups in the trigger.

  • Unit Variables
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Group1=[1,2,3] --------
      • Set VerdantCounter_i2 = 1
      • Set VerdantSpiritUnits_uArray[1] = Verdant Spirit 1234 <gen>
      • Set VerdantSpiritUnits_uArray[2] = Verdant Spirit 1235 <gen>
      • Set VerdantSpiritUnits_uArray[3] = Verdant Spirit 1236 <gen>
      • For each (Integer VerdantCounter_i) from 1 to 3, do (Actions)
        • Loop - Actions
          • Unit Group - Add VerdantSpiritUnits_uArray[VerdantCounter_i] to VerdantUnits_ugArray[VerdantCounter_i2]
          • Game - Display to (All players) the text: ((String((Number of units in VerdantUnits_ugArray[VerdantCounter_i2]))) + units in Counter Group)
          • Game - Display to (All players) the text: ((String((Number of units in VerdantUnits_ugArray[1]))) + units in Value=1 Group)
      • -------- Group2=[4,5,6] --------
      • Set VerdantCounter_i2 = 2
      • Set VerdantSpiritUnits_uArray[4] = Verdant Spirit 1246 <gen>
      • Set VerdantSpiritUnits_uArray[5] = Verdant Spirit 1247 <gen>
      • Set VerdantSpiritUnits_uArray[6] = Verdant Spirit 1248 <gen>
      • For each (Integer VerdantCounter_i) from 4 to 6, do (Actions)
        • Loop - Actions
          • Unit Group - Add VerdantSpiritUnits_uArray[VerdantCounter_i] to VerdantUnits_ugArray[VerdantCounter_i2]
          • Game - Display to (All players) the text: ((String((Number of units in VerdantUnits_ugArray[VerdantCounter_i2]))) + units in Counter Group)
          • Game - Display to (All players) the text: ((String((Number of units in VerdantUnits_ugArray[2]))) + units in Value=2 Group)
      • -------- Group3=[7] + patrol --------
      • Set VerdantCounter_i2 = 3
      • Set VerdantSpiritUnits_uArray[7] = Verdant Ancient 1249 <gen>
      • Unit Group - Add VerdantSpiritUnits_uArray[7] to VerdantUnits_ugArray[VerdantCounter_i2]
      • Set VerdantPatrolPoint_Tempp1 = (Center of PrimalLushPatrol p1 <gen>)
      • Unit - Order VerdantSpiritUnits_uArray[7] to Patrol To VerdantPatrolPoint_Tempp1
      • Custom script: call RemoveLocation(udg_VerdantPatrolPoint_Tempp1)
      • -------- Group4=[8,9,10] --------
      • Set VerdantCounter_i2 = 4
      • Set VerdantSpiritUnits_uArray[8] = Verdant Ancient 1237 <gen>
      • Set VerdantSpiritUnits_uArray[9] = Verdant Spirit 1238 <gen>
      • Set VerdantSpiritUnits_uArray[10] = Verdant Spirit 1239 <gen>
      • For each (Integer VerdantCounter_i) from 8 to 10, do (Actions)
        • Loop - Actions
          • Unit Group - Add VerdantSpiritUnits_uArray[VerdantCounter_i] to VerdantUnits_ugArray[VerdantCounter_i2]
      • -------- Groupp5=[11,12] --------
      • Set VerdantCounter_i2 = 5
      • Set VerdantSpiritUnits_uArray[11] = Verdant Spirit 1250 <gen>
      • Set VerdantSpiritUnits_uArray[12] = Verdant Spirit 1251 <gen>
      • For each (Integer VerdantCounter_i) from 11 to 12, do (Actions)
        • Loop - Actions
          • Unit Group - Add VerdantSpiritUnits_uArray[VerdantCounter_i] to VerdantUnits_ugArray[VerdantCounter_i2]
      • -------- Groupp6=[13] --------
      • Set VerdantCounter_i2 = 6
      • Set VerdantSpiritUnits_uArray[13] = Verdant Ancient 1252 <gen>
      • Unit Group - Add VerdantSpiritUnits_uArray[13] to VerdantUnits_ugArray[VerdantCounter_i2]
      • -------- Groupp7=[14] --------
      • Set VerdantCounter_i2 = 7
      • Set VerdantSpiritUnits_uArray[14] = Verdant Spirit 1253 <gen>
      • Unit Group - Add VerdantSpiritUnits_uArray[14] to VerdantUnits_ugArray[VerdantCounter_i2]
      • Game - Display to (All players) the text: Ran Unit Variables
Edit: Hid the trigger in some nice tags to appease the Great Forum Gods/admins.
 
Level 7
Joined
May 15, 2009
Messages
192
What number is your unit group array set to in the variable editor ? If you use 14 it needs to be at 14.

Right, thx. I'll try that (I always forget about Variables Values)
Will report back in a bit (editing this post)

Edit: Works! Thanks alot (rep awarded already) - Set the Unit Variable Value to 14, and the Group Variable Value to 7. Thanks for the tip.
 
Last edited:
Right, thx. I'll try that (I always forget about Variables Values)
Will report back in a bit (editing this post)

Edit: Works! Thanks alot (rep awarded already) - Set the Unit Variable Value to 14, and the Group Variable Value to 7. Thanks for the tip.

unit variables should only be set to 1. Unit groups need to be set to 7 unless you create them in the triggers.
 
Status
Not open for further replies.
Top