Difference between revisions of "Variables"

From HIVE
Jump to navigation Jump to search
m
 
Line 89: Line 89:
  
 
[[Category:StarCraft II]]
 
[[Category:StarCraft II]]
 +
[[Category:Triggers]]
 
[[Category:Reference]]
 
[[Category:Reference]]
[[Category:Triggers]]
 

Latest revision as of 10:21, 27 March 2013

Variables are used to store information that you will be able to call later on. This information can be pretty much anything from units to players, passing by regions, orders, sounds, and much much more.

To create a variable, right click the left area in the Trigger Window, go to New, then New Variable (Ctrl + B). Now you need a type, a name, and sometimes a value or configure it to be an array.

Variables Basics

Writing to a variable is as simple as making a new action, and choosing the option that first comes up, which is 'Set Variable'. When setting a variable, the editor will automatically populate the list with reasonable things to put into it.

When reading a variable, conditions vary. Bringing a unit to a location can also be done by bringing a variable to a location, if the unit is inside the Unit variable. Even math can be done, in the math section of the conditions list, to variables containing numbers and can allow you to do more things in only one trigger.

Local Variables

A Local Variable is a variable that you will only be able to use within the one trigger that contains it.

Global Variable

A Global Variable is used to transcend the boundaries of the triggers, thus allowing you to use it anywhere. They are created on the left-tree, where triggers and folders are listed.

Arrays

Arrays are extremely useful and time-saving when you learn to use them properly. They are used to store different information into the same variable. Let's say you have a Variable that you want to change based on what different players do, but you don't want the changes one player makes to affect the variable for another player. By checking the box next to "Array" and setting the size to the amount of players in your game, you can then link to whateverVariable[1] and have that specifically be for Player 1's triggers, then set up whateverVariable[2] for Player 2, and so on. Of course this also isn't limited to something as simple as that. Arrays are most helpful when you just want to keep your variables organized and minimal rather than having to create a ton of variables that serve a similar purpose.

Constants

A Constant "type" variable is one that you will not be able to change. You set its initial value, and it'll always stay as it is.

Variable Types