• 🏆 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!

Is there any way to do this? (Get Array Number)

Status
Not open for further replies.
Level 8
Joined
Jul 17, 2004
Messages
283
  • Events
    • Unit - A unit Acquires an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Change Job to Archer
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Or - Any (Conditions) are true
          • Conditions
            • (Triggering unit) Equal to Soldier[1]
            • (Triggering unit) Equal to Soldier[2]
            • (Triggering unit) Equal to Soldier[3]
      • Then - Actions
        • Unit - Remove (Triggering unit) from the game
        • Unit - Create 1 Archer for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing 270.00 degrees
        • Set Soldier[X] = (Last created unit)
      • Else - Actions
What I'm trying to do is set the Soldier[X] variable to the unit that changed their job. Wat do?
 
  • Events
    • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Change Job to Archer
    • Actions
      • For each (Integer A) from 1 to 3 do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to Soldier[(Integer A)]
            • Then - Actions
              • Unit - Remove (Triggering unit) from the game
              • Unit - Create 1 Archer for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing 270.00 degrees
              • Set Soldier[(Integer A)] = (Last created unit)
              • Skip Remaining Actions
            • Else - Actions
The "Skip Remaining Actions" isn't necessary, but I put it there anyway. The trigger above is basically doing the same thing. "Or" conditions kind of behave like this:
If (condition A) -> do actions. else, check (condition B)
If (condition B) -> do actions. else, check (condition C)
If (condition C) -> do actions. else, check (condition D)....

So forth. In your case, you can model it with a loop since your conditions are all the same except for the index.

Also... make sure you switch (Integer A) with your own variable. Just in case. If you need an explanation just ask me in chat.
 
You also could use hashtables.. could be useful if you often use loops to find the index.


  • Actions
    • Hashtabelle - Create a hashtable
    • Set Hashtable = (Last created hashtable)
    • For each (Integer A) from 1 to 3, do (Actions)
      • Schleifen - Aktionen
        • Hashtabelle - Save (Integer A) as Index of (Key (Owner of Footman[(Integer A)])) in Hashtable
Here you save the index of footman into your hashtable


  • Events
    • Unit - A unit acquires an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Change Job to Archer
    • Or - Any (Conditions) are true
      • Conditions
        • (Triggering unit) Equals Footman[1]
        • (Triggering unit) Equals Footman[2]
        • (Triggering unit) Equals Footman[3]
  • Actions
    • Set Point = (Position of (Triggering unit))
    • Unit - Create 1 Archer for (Owner of (Triggering unit)) at Point facing 0.00 degrees
    • Set Footman[(Load Index of (Key (Owner of (Triggering unit))) from Hashtable)] = (Last created unit)
    • Unit - Remove (Triggering unit) from the game
    • Custom script: call RemoveLocation (udg_Point)
    • Custom script: set udg_Point = null
So you can just load the index out of the hashtable depending on which Footman enters


But if you only need it for this single trigger, it's maybe no worth to use hashtable for this.. I guess looping from 1-3 is then would be better here.
 
Status
Not open for further replies.
Top