Variables allow you to store pieces of information for later use. Normally, SEXP trees use fix values. Consider this basic one:
is-destroyed-delay 2 GTT Spomer send-message #Command High Spomer destroyed
All these values are fixed. If you wanted Command to send a message five (not two) seconds after the Spomer is destroyed, you would need a second Event with 5 instead of 2. If, however, the "delay" value (2) were a variable, you could manipulate the delay between the Spomer's death and Command sending the message in a more convenient and flexible way in one Event. Variables are dynamic values that can be changed during the course of the mission.
Right-click on any argument in the Events list and look at the three options at the bottom of the menu, Add Variable, Modify Variable, and Replace Variable. If your Events window is empty, create an Event.
- Add Variable allows you to create a new variable. If you're using FreeSpace Open, your Add Variable window looks like the image above. You can add a number or a string-based variable. Number-based variables must contain numbers only, while string-based values can use letters. From a technical point of view, it's unimportant how you name your variable. Then set your variable's default value.
- In our example, let's create a number-based variable that is named "TurretsDown" and its default value is 0.
- Modify Variable allows you to change a variable that you've already created. You can modify only one variable at a time. This feature is not to be confused with the modify-variable one.
- Replace Variable replaces the currently selected SEXP argument with the variable of your choice.
- If you clicked on "0" in the example, you could change it to TurretsDown using Replace Variable --> TurretsDown. If the "0" is changed to TurretsDown (which receives a red icon), then you've been successful. Now the Event will come true if TurretsDown equals 3.
Variable values can be changed using the modify-variable SEXP, which you can find under Add Operator --> Change --> Special. A sample Event that adds 1 to a number-based variable looks like:
Four Types of Variables
There are four types of variables.
Standard variables This type of variables are used in one mission only. If the player ends the mission in any way (jumping out, dying, restarting, etc.), all the standard variables will be reset to their default values. Whether the player is allowed to progress in the campaign or not is inconclusive (compare campaign-persistent variables).
Player-persistent: Player-persistent variables always retain the last value you gave them, regardless of the outcome of the mission. They are reset upon the reset of the current campaign, or the selection of a new campaign.
Campaign-persistent: These persistent variables are stored in the campaign file, and are only stored when a campaign progresses to a new mission. So if the player is killed or quits during a mission, and changes made to a campaign-persistent variable are not stored.
Network variables are only relevant in a multiplayer game. Non-network variables are only ever altered on the server. This means that they can not be used in messages or scripting because all the client machines will only ever have the default value. If you need to have the value of a variable display in a message you will need to mark it as a network variable.
Variables and Messages
Variables can also be used in messages. To do this, use the variable's name preceded by the '$' token (for example "$killcount"), and in-game this will be replaced with the value of the variable. Input is case-sensitive. It works for both numeric and string variables.
- Main Article: Variables example mission
This is a mission in which the player must take down all four of the Sathanas's main beam weapons to win the mission. This is like Bearbaiting, except this mission is solely made as a variables tutorial. The juggernaut will not fire at you or jump out.