• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Brainstorm Best Way to Store and Use 'Race' Variables

Status
Not open for further replies.
Level 22
Joined
Mar 16, 2008
Messages
1,036
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.
 
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.
Back
Top