Variable

From FreeSpace Wiki
(Redirected from Persistent Variables)
Jump to: navigation, search

Variables (also called SEXP variables) allow you to store pieces of information for later use. Normally, SEXP trees use fixed 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.

Basics

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.

The Add Variable window
  • 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:

VariableEvent.JPG

Four Types of Variables

There are five types of variables. Hover the mouse over each variable name in the variable window to display additional information.

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). This is the default variable type, and requires no boxes to be checked in the variable window.

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.

Save on Mission Complete: A type of persistent variable that will save when the player clicks Accept to go to the next mission. If the player is killed or quits during a mission, and changes made to this variable are not stored. They are reset upon the reset of the current campaign, or the selection of a new campaign.

Save on Mission Close: A type of persistent variable that will save when the player leaves the mission. If the player is killed or quits during a mission, and changes made to this variable are stored. They are reset upon the reset of the current campaign, or the selection of a new campaign.

Eternal: Eternal is a flag you can add to BOTH 'Save on Mission Complete' and 'Save on Mission Close' to tell the game to not delete that variable even if the campaign ends or a different campaign is started. It does not reset upon the end of the current campaign, or the selection of a new campaign. Thus it can be used and referred to by other campaigns.

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.

Example Mission

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.

See Also

Links