Way Of
    The Wombat


3.0 Variables
3.1 Defining Variables
3.2 Built-in Variables
3.3 Using Variables in Functions
3.0 Variables

Variables in algebraic mathematics are numbers assigned a name, because their actual values can change, or are unknown. In SLIC, this is much the same, only as well as integer variables (NB integers not fractions or decimals: SLIC cannot use them), SLIC also uses unit variables, army variables, location variables and city variables. Player variables are usually treated as integers.

In the event GetExpelledOrder(army_t, location_t, int_t<player>), the event stores three variables, and these are denoted by army_t, location_t, int_t<player>. They are stored in the game as army[0], location[0] and player[0]. When this event occurs, you can pass the variables into functions, to get them to work properly. (see chapter 5).

3.1 Defining Variables

To make SLIC recognise the variables for what they are, so that it doesn't start treating a unit as a city, or a location for an integer, you have to define what each variable that you use is. This can be done inside the handler, or outside the code, on its own. The former is a local variable. It applies only to that handler. If you use it in another handler, you must redefine it. The latter is a global variable, it applies to all functions and handlers in the code, and can be used in messagebox text (see chapter 6).

The advantages of global variables is that they can be used over more than one handler, to store a variable globally. If you do not really need to pass the variable between handler, then you are better off using local variables, to avoid confusion with other SLIC, and to save memory.

NB. If you are mixing your SLIC with that of other peoples, chances are you may have used the same variables somewhere, so it is recommended to define variables locally, unless you need them global for some reason, in which case name them with really obscure names, or use your initials as a prefix, eg IW_tmpPlayer instead of tmpPlayer.

To define a variable, you need a new line, to tell the game what each variable is. e.g:

int_t tmpNum; // tmpNum is an integer int_t tmpPlayer // tmpPlayer is an integer // players and ints are both treated as integers unit_t tmpUnit; // tmpUnit is a unit location_t tmpLoc; // tmpLoc is a location army_t tmpArmy; // tmpArmy is an army city_t tmpCity; // tmpCity is a city // note semicolons at the end of each line

Once they are defined, variables can be used below that point. Most SLIC files keep global variables at the very top, so they apply to the whole code.

3.2 Built-in Variables

Activision Built-In Variable Listing

As mentioned in chapter 2.1, there are built-in SLIC arrays. These come with "member" variables that are already defined. Each unit variable for instance automatically contains knowledge of the unit owner (a player), location (a location), type (an integer), hit points (an integer), name (a text string), and a member called .valid, which is either 1 or 0 depending on whether the unit you stored earlier still actually exists on the map.

They can be used as a suffix to any other defined variable eg. if tmpCity is defined as a city, tmpCity.owner will automatically give you the player who owns the city.

Because integers and players are not completely interchangeable, you cannot use the built-in variables on players you have defined. Before, you defined a player as int_t tmpPlayer; or similar. Integers have no built-in members, so you must first find the player corresponding to that number, and store it in a player array - a true player. This is quite simply:

player[2] = tmpPlayer;
I used player[2] because it is unlikely to have been used by the game at that point, wheras player[0] and player[1] may be.

Then you can use player[2].cities to find the number of cities that tmpPlayer owns.

3.3 Using Variables

Related to function usage in chapter 5, but functions need to have the correct variables put into them.

HandleEvent(SleepUnit) 'kill_the_unit' pre { unit_t tmpUnit; // define variable tmpUnit = unit[0]; // make tmpUnit equal unit[0] KillUnit(tmpUnit); // The KillUnit(unit_t) needs to have a unit_t in it // In this case, your unit_t could be either unit[0] // Or the unit_t you defined: tmpUnit }
Using the Activision function reference, you can see which functions need which variables, and make sure you have the right ones available and defined abnd then put them into the function parentheses () in the correct order, separated by commas.

back close forward