• 🏆 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] Set variable to index of array

Status
Not open for further replies.
Level 7
Joined
Jun 1, 2009
Messages
104
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 28
Joined
Feb 18, 2014
Messages
3,579
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