Difference between revisions of "Variables"

From FreeSpace Wiki
Jump to: navigation, search
(moved contents from "persistent variables" to this page)
(removed statement saying that variables have been around since fs1. they were implemented in retail fs2.)
Line 1: Line 1:
Variables can be a powerful FRED tool, although are often more of a convenience than an absolute necessity. FREDers use variables for the same two reasons that programmers do. One, they allow you to easily store pieces of information for later use. Two, they let you avoid hard-coded or "magic" numbers for arguments that you use several times in your mission's events.
+
Variables, implemented in retail FS2, can be a powerful FRED tool, although are often more of a convenience than an absolute necessity. FREDers use variables for the same two reasons that programmers do. One, they allow you to easily store pieces of information for later use. Two, they let you avoid hard-coded or "magic" numbers for arguments that you use several times in your mission's events.
  
 
Using variables is simple. You can use variables in place of any SEXP argument where you would normally use a string or number. Right-click on  the argument in the Events list and look at the three options at the bottom of the menu, '''Add Variable''', '''Modify Variable''', and '''Insert Variable'''. Click '''Add Variable''' to create a new variable. '''Modify Variable''' allows you to change a variable that you've already created. '''Insert Variable''' replace the currently selected SEXP argument with the variable of your choice.
 
Using variables is simple. You can use variables in place of any SEXP argument where you would normally use a string or number. Right-click on  the argument in the Events list and look at the three options at the bottom of the menu, '''Add Variable''', '''Modify Variable''', and '''Insert Variable'''. Click '''Add Variable''' to create a new variable. '''Modify Variable''' allows you to change a variable that you've already created. '''Insert Variable''' replace the currently selected SEXP argument with the variable of your choice.
Line 12: Line 12:
  
 
'''Network-persistent''' variables are only relevent in a multiplayer game. They affect all players in the current game. ''Someone with multiplayer experience, please expand on this.''
 
'''Network-persistent''' variables are only relevent in a multiplayer game. They affect all players in the current game. ''Someone with multiplayer experience, please expand on this.''
 
==Variables do exist; use them==
 
 
There are many "hackish" ways to avoid variable use that can be seen in some of the older FRED tutorials, "back then" when people where ignorant of variables (which have existed since FreeSpace 1). Many people are still new to FRED and may suggest overcomplicated solutions to problems that could more easily be solved using variables. For example, some of the older FRED tutorials posit that you can see how many waypoints a player has reached (in any order) by placing a wing of invisible fighters far out of the play area and tie each fighter in the wing to self-destruct as a waypoint is reached. You can then use the percent-ships-destroyed SEXP on the wing to see how many waypoints have been reached, as there's no SEXP to answer this question directly. This is a primitive solution to the problem, and it's an example of where variables could easily be used to get the same effect.
 
  
 
''Fred Zone examples of uses for variables''
 
''Fred Zone examples of uses for variables''

Revision as of 16:38, 10 March 2008

Variables, implemented in retail FS2, can be a powerful FRED tool, although are often more of a convenience than an absolute necessity. FREDers use variables for the same two reasons that programmers do. One, they allow you to easily store pieces of information for later use. Two, they let you avoid hard-coded or "magic" numbers for arguments that you use several times in your mission's events.

Using variables is simple. You can use variables in place of any SEXP argument where you would normally use a string or number. Right-click on the argument in the Events list and look at the three options at the bottom of the menu, Add Variable, Modify Variable, and Insert Variable. Click Add Variable to create a new variable. Modify Variable allows you to change a variable that you've already created. Insert Variable replace the currently selected SEXP argument with the variable of your choice.

Three Types of Variables

There are three types of variables.

Player-persistent: This type of persistent variable is stored in the pilot file. Further, they are stored immediately when they are created/changed from within a mission. This means that any change is going to be there regardless of the later outcome of the mission. Player-persistent variables can be accessed and changed from any campaign played with the same pilot.

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-persistent variables are only relevent in a multiplayer game. They affect all players in the current game. Someone with multiplayer experience, please expand on this.

Fred Zone examples of uses for variables

Example 1

Example 2