Variables?
The problem with variables is that it's hard to explain what you use them for. FRED's SEXPs are pretty powerful so variables tend to only be used when you come across a problem you can't solve any other way or which would be complicated to solve without them. That means that trying to come up with an example of how you use a variable means that you have to come up with a pretty detailed example.
The FRED2 Walkthrough has a good example of how to use a variable. In that mission you have 4 troop transports attempting to capture an orion. The transports will dock with the Orion. Spend a little while disgourging troops and then undock. If two of the troopships manage to successfully dock with the Orion then the orion is captured by the enemy forces. In the walkthrough they used variables as a way of achieving this. Basically they defined a variable called DockCount and added 1 to it every time one of the troop transports managed to successfully dock. When the value of the variable was 2 then the Orion could be captured and a simple when DockCount = 2 type event could be used to test this.
Although the walkthrough shows a good example of how to use a variable it's not the best example as though it would be a little tedious this example could have been made using normal SEXPs (basically a big OR checking that two transports made it)
So lets suggest something a little more complicated. Lets say that you want to say a certain number of soldiers are on the Orion. Let's say that it doesn't matter if the troop transport managed to get undocked safely since they are in battle armour. All that matters is the time the transports managed to stay docked to the Orion.
Now that is pretty much impossible without variables. With them. Well it's not easy but it's possible.
First you set up a variable called timedocked (with an inital value of 0). Then you set up a repeating event for each transport (Lots of repeats, repeat every second).
When
-and
--Has-Docked-Delay
---Transport x
---10 (lets say it takes 10 seconds after docking to open the airlock etc before troops start moving into the Orion)
--not
---has-undocked-delay
----Transport x
----0
-Modify-Variable
--TimeDocked
--- +
----TimeDocked
----1
Basically that event waits until the transport has been docked for 10 seconds and then adds 1 to the value of TimeDocked every second until the ship undocks.
Then you have an event like this
When
- =
--TimeDocked
--100
-do-whatever
That event triggers whenever timeDocked reaches 100 seconds regardless of whether each ship stayed docked for 25 seconds, one ship managed a full 100 seconds or any other combination you can think of. As you can see there is no way you could do that without variables
That's number variables. I've not used String variables because so far I've always wanted to use a SEXP with them that they don't like (For instance =. You can't test a String variable to see if it's equal to another string variable which basically rules them out for a lot of uses. Sesq may have a few good examples of their use.
If you're using FS2_Open you'll have access to persistant variables. These aren't reset at the end of a mission so they can be used in a campaign to do something like having something occur in Mission 12 based on a value from mission 4. (For instance have a cruiser take longer to appear depending on how badly shot up it was in the earlier mission). I've already written an example of how to use PV's
here.