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

Brainstorm Best Way to Store and Use 'Race' Variables

Status
Not open for further replies.
Level 21
Joined
Mar 16, 2008
Messages
955
I'm working on a new small project that will create starting units based on a players race.

My first idea was store race as variable then use a ton of if statements to create the right units for the player. Anyone have more efficient ideas before I go through with this?

Thank you for reading.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Arrays and/or Hashtables will pretty much always be the solution. An index can represent a Race and it's values can be associated with the Race.

And the easiest method that comes to mind would be to use a Trigger and Race array to do something along the lines of this:

Setup trigger:
  • Set Variable Race_Type[1] = Human
  • Set Variable Race_Type[2] = Orc
  • Set Variable Race_Trigger[1] = Spawn Human Units <gen>
  • Set Variable Race_Trigger[2] = Spawn Orc Units <gen>
  • Set Variable Race_Total = 2
Player has picked a race and is spawning in trigger:
  • Set Variable PLAYER = (The player)
  • Set Variable PN = (Player number of PLAYER)
  • For each Integer LOOP from 1 to Race_Total do
    • Loop - Actions
      • If (Race of PLAYER) Equal to Race_Type[LOOP] then Trigger - Run Race_Trigger[LOOP] (ignoring conditions)
You would switch Race_Type to an Integer variable or String variable if you plan on having custom races.

A specific race trigger:
  • Spawn Human Units
    • Events
    • Conditions
    • Actions
      • Unit - Create 5 Footman for PLAYER at PLAYER_START_POINT[PN] facing...
 
Last edited:
Status
Not open for further replies.
Top