Difference between revisions of "Variables"

From HIVE
Jump to navigation Jump to search
 
m (1 revision: StarEdit.net Wiki)
(No difference)

Revision as of 06:16, 21 November 2010

Variables are used to store information into something that you will be able to call later on. This information can be pretty much anything (not just numbers!), from units to players, passing by regions, orders, sounds, and much much more. For a complete list of the Variable Types, please click here.

The Variables themselves contain 4 important notions: Local variables, Global variables, Arrays and Constants.

Local

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

Global

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 informations into the same variable.

What is the difference between having 10 different variables and 1 variable with 10 arrays? Well, with the arrays, you can use an Integer to call data, which will save you a lot of time.

The Trick

To prevent errors, it is always recommended to add 1 more array size than what you really need. Why? Because the Array #1 is [0]... this is really misleading. For example, if you have 4 Players and want to use arrays to differentiate a variable from these 4 players, you'll probably want to make it Var[1], Var[2], Var[3] and Var[4]. However, if you have set the Array Size of the variable "Var" to 4, the last array will be Var[3] (the first one would be Var[0]), and thus trying to set an information into Var[4] will cause problems. But if you set the Array Size to 5, you'll be able to just not use the first array (Var[0]) and thus store information into the 4 others being Var[1], Var[2], Var[3] and Var[4].

It is also very useful for when it comes to "Picked integers". Indeed, if you're using a "Pick Each Integer" action to make some actions run, for example, for 10 players, you'll want to make the editor pick the integers between 1 and 10, inclusively. But if you try to use "Picked integer" for a Player number and a variable array (which is wise!), you'll have to have the variable have an array size of 11, because you cannot do Var[Picked Integer - 1].

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.

Most used types

Among the pretty long list of Variable Types, there of course are some types you'll use more often than others. Here's an arbitrary list:

See Also