They can be somewhat confusing, so lets see if I can clear it up. Might as well start from the beginning I guess.
1) Adding variables to a mission: To do this, you enter the events editor and right-click on an event, then select
Add Variable. Any event, it doesn't matter, as variables
are not tied to the events you click on to add them, that's simply how you access the command to do it.
Once you have done that, a window pops up where you can select the type (string or number), the name (how you access it later from events), the default value (this is the value of the variable before any operations are carried out on it. Also, it's what the variable's value is displayed as in FRED - This never changes unless the default does, so don't fret), and where you will also find checkboxes for making the variable player- or campaign-persistent (we'll ignore those here).
The type has to fit what you intend to use it for of course (string for a ship name for example, number if you want to count the number of times a ship has been disabled in the mission), and the name obviously should be descriptive of that as well. The default value is something you will need to set depending on how you use it, but it can be modified later once you know what you need it to be.
Once all field are filled out, click ok and the window will disappear as if nothing had happened. Now right click an event again, and a new option has shown up:
Modify Variable. Select this and you go back to the window you had before, only the name field is now a dropdown box where you can select any variable in the mission. Here, you can alter things like the default value mentioned before, so this is where you will go once you know what you need it to be.
2) Accessing variables with events: Once you have your variables laid out ready for use, there are two ways to access them from within the events system. A) Using the variable's value directly in an evaluation or operation, by right-click on the item you want to replace with a variable and select the now-available
Replace Variable option, and B) Using the
modify-variable SEXP found under change->special. The latter of those can also involve the former, as you can use an arithmetic operation as part of that SEXP.
Now, what can we use this for?
The first and most obvious use is counting - In the example the walkthrough uses you have a number of transports docking with an Orion, and variables are used to keep track of how many of them survive. It's actually a very good example, but just not very well explained, so I'll try to explain it properly in the context of what I've already said earlier:
The first thing we see is the window that comes up when you add a variable. We can see that it's initialized to 0, which is because we want to count up from 0 until we've reached the number of transports required for a capture, in this case two.
Now look at the first event of the Sleipner chain ("Sleipner 1 done"). All the stuff that actually happens in unimportant, what matters is the bit at the end. Here, the variable created before is incremented by one, by using the modify-variable SEXP combined with a "+" arithmetic SEXP to add 1 to the existing value of the variable. This is then done for each transport, with the result that each transport that successfully docks raises the value of the variable by one.
The next part of the Sleipner chain is two events ("Relentless boarded" and "Relentless captured") that rely on the value of this variable to determine when they go off. Here you see the variable used in an evaluation without being modified in any way, and you also start to see why variables were the best solution here: There's no need for a complicated evaluation or chained events to make sure they go off in the right sequence, and no need to keep track of every single transport individually. It's very simple, when the counter variable hits 1, one of the transports (could be any one of them) has docked and the first event should go off, and when it hits two, two of them have docked and the second event should go off, and that's all you need to worry about since variables were used.
I hope that explains it a bit better than the walkthrough did. Another example of using a number variable to count can be found on
This Wiki Page, where variables are used to effect a delay in an event chain by counting seconds.
Now, string variables are esentially no different, except you can't count with them: They can substitute text just like number variables can substitute numbers. For example, if you want a wingman to send a message, but are worried he might be dead, you could use a string variable in place of the ship name in the send-message SEXP, and modify that variable to a different ship name in case your first choice got killed prematurely.
That'll do for now, as I'm hungry and need food. Hope it helps
