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

Why i cannot set random 1 unit as TempUnit from TempGroup?

Level 18
Joined
Jun 2, 2009
Messages
1,236
  • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Player((Integer A)))) and do (Actions)
    • Loop - Actions
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Multiple ConditionsOr - Any (Conditions) are true
            • Conditions
              • (Unit-type of (Picked unit)) Equal to (==) TestStructure1
              • (Unit-type of (Picked unit)) Equal to (==) TestStructure2
              • (Unit-type of (Picked unit)) Equal to (==) TestStructure3
              • (Unit-type of (Picked unit)) Equal to (==) TestStructure4
        • Then - Actions
          • Unit Group - Add (Picked unit) to TempGroup
          • Game - Display to (All players) for 2.00 seconds the text: (picked + (Name of (Picked unit)))
          • Set TempUnit = (Random unit from TempGroup)
          • Game - Display to (All players) for 1.00 seconds the text: (Name of TempUnit)
I can see the name of Picked Unit but it says (null) when i do this.
Set TempUnit = (Random unit from TempGroup)
Why i cannot get random unit from TempGroup?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,886
You probably want to do something like this:
  • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Player((Integer A)))) and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Unit-type of (Picked unit)) Equal to TestStructure1
              • (Unit-type of (Picked unit)) Equal to TestStructure2
              • (Unit-type of (Picked unit)) Equal to TestStructure3
              • (Unit-type of (Picked unit)) Equal to TestStructure4
        • Then - Actions
          • Unit Group - Add (Picked unit) to TempGroup
          • Game - Display to (All players) for 2.00 seconds the text: (picked + (Name of (Picked unit)))
        • Else - Actions
  • Set TempUnit = (Random unit from TempGroup)
  • Game - Display to (All players) for 1.00 seconds the text: (Name of TempUnit)
So you fill TempGroup with all of the different TestStructures. Then after that's finished you try to get one at random.

If TempGroup is empty then TempUnit will be set to "No unit", so you may want to check for that:
  • Set TempUnit = (Random unit from TempGroup)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • TempUnit Not equal to No unit
    • Then - Actions
      • -------- We found a random unit --------
    • Else - Actions
      • -------- We could NOT find a random unit --------
 
Last edited:
Top