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

[Solved] Set variable to index of array

Status
Not open for further replies.
Level 7
Joined
Jun 1, 2009
Messages
125
Any chance to set a variable to index from Unit[index] array?
Custom value ofc is occupied by another functions

  • example
    • Events
      • Unit - A unit enters A00 <gen>
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Triggering unit) Equal to Spawn_Hero_Unit[1]
        • Then - Actions
          • Set VariableSet Chosen_Int = (Chosen_Int + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Triggering unit) Equal to Spawn_Hero_Unit[2]
        • Then - Actions
          • Set VariableSet Chosen_Int = (Chosen_Int + 2)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Triggering unit) Equal to Spawn_Hero_Unit[3]
        • Then - Actions
          • Set VariableSet Chosen_Int = (Chosen_Int + 3)
        • Else - Actions
I want to set Chosen_Int + index directly, if it even possible. Instead of hundreds of strings make the only one.
 
Level 30
Joined
Feb 18, 2014
Messages
3,623
Just create an integer variable that counts the max of Spawn_Hero_Unit then do this :
  • Trigger
    • Events
      • Unit - A unit enters Region 001 <gen>
    • Conditions
    • Actions
      • For each (Integer A) from 1 to MaxSpawnHeroUnit, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to Spawn_Hero_Unit[(Integer A)]
            • Then - Actions
              • Set VariableSet Chosen_Int = (Chosen_Int + (Integer A))
            • Else - Actions
 
Status
Not open for further replies.
Top