Using SEXPs to make missions

Although you can make a simple mission without them the only way to build anything worth playing is to use SEXPs. The quickstart is an example of the limits of what you can build without them, sure you could stick a few battlestars and basestars in it but that would be about all you could do.

Learning to master SEXPs is pretty much the most important technical skill you need to develop in order to be a good mission designer. Most of your work making a mission involves figuring out which SEXPs you need, and in which order to put them.

Given all that, it's fortunate that SEXPs aren't actually that hard to work with at all!

(By the way, there is some debate about whether SEXP is pronounced "ess XP" or "sex pee", although using the latter does get you much stranger looks in public!)

What do SEXPs do?

Most SEXPs do one of two basic things. They either make something happen (like turning a friendly ship hostile, sending a message, etc) or they test to see if something has happened (which ships have been destroyed, how much time has passed, what cargo has been inspected, and so forth). This second kind can be further split depending on what kind of information they come back with. Many of them return true or false answers (Has ship x been destroyed?) while other return numbers (What is the distance between ship x and ship y? How many missiles does the player have left?).

So let's take a look at an example of a SEXP. Sample SEXP

This SEXP checks if a ship named Raptor 1 has jumped out yet. The name of the SEXP itself is has-departed-delay. Next to it's name you'll see the letters op in red. This denotes that this is a SEXP Operator (basically what we've been calling a SEXP until now). Below that we have the SEXP's arguments. SEXPs have a variable number of arguments depending on what they do. This SEXP checks how long ago a ship jumped out. That means that it is useless unless we actually tell it which ship we're interested in. In this case, the arguments are a delay (3 seconds) and then the name of the ship. So this SEXP will wait until 3 seconds after the Raptor jumps and then will change to true.

Example of an action SEXPHere's an example of a SEXP that does something, rather than testing for something. In this case the SEXP add-goal has another SEXP ai-chase-ship as one of it's arguments. This is very common. Basically this SEXP tells Cylon Raider 1 to chase after Red 1 and try to kill it.

When using the Events Editor, you will come across the 3rd kind of SEXP, the conditional operator. All this does is say IF x is true, DO y. Here's an example which shows all 3 kinds of SEXP.

Example of an EventIn this case when is the conditional. It has two parts, the trigger and the action. When the Pegasus is destroyed the trigger will now be true and the action (sending a message from the Galactica) will happen. You may have noticed the words Pegasus Destroyed above the SEXP. The Events Editor allows you to put a name above each conditional operator for easy reference. The whole things is now called an Event.

Events help organise the SEXPs in your mission. Since triggers can get very complex, you can test if events have triggered using the is-event-true-delay SEXP. This helps you avoid having to duplicate the entire trigger again.

Events have 3 possible states. True (The trigger resolved to true at one point), False (FS2_Open has determined that the event can never come true. A ship required to jump out has been destroyed for instance) and Incomplete (At the start of the game, most SEXPs will be in this state, waiting to be triggered).

Events can also be set to repeat. The trigger will be tested again and if it is still true, the event will happen again.

SEXP Popup Menu

SEXP Popup MenuIn any editor where you have to deal with SEXPs, you can popup this menu with a right mouse click.

Edit Data can be used whenever you have data selected. It allows you to rename the data to whatever is appropriate. It's not used very often cause a pair of single clicks will have the same effect.

Expand All will expand all the nodes of this particular SEXP allowing you to see all the arguments and data it has. Basically it is the same as pressing on the little + sign and then on all the + signs that appear below that one.

BeforeExpand All : Before AfterExpand All : After

Cut, Copy and Paste work pretty much exactly how you would expect them to for text, but they can also be used for SEXPs. Be warned that in order to use Paste you must replace an existing SEXP. If you don't want to replace you must use Add Paste instead.

Caution : Accidentally using Paste when you meant to Add Paste is a common source of annoyance to FREDders and can easily wipe out an event you spent quite a while building. To make matters worse, the Undo option doesn't work in the Events Editor! It's another reason why you should save every few minutes.

Add Operator will add another operator to the event. You will be presented with a menu showing all the possible operators you can add.

Note : If you want to have an and or an or SEXP with more than 2 conditions, you'll need to use this to add the 3rd one.

Insert Operator will place another operator between the currently selected one and the SEXP above it (or event name).

Replace Operator will replace the current operator with a new one. If the two Operators are compatible all the data will be retained, otherwise all the data will wiped. The example below shows that data is retained when swapping AND and OR SEXPs.

BeforeStarting Event After AddAdd After InsertInsert After ReplaceReplace

Add Data and Replace Data work in much the same way but add/replace ships names, weapons, waypoints, etc instead of SEXPs.

Replace Variable allows you to replace any piece of data with a variable. It will be grayed out until you actually create a variable.

Modify VariableThe Add Variable Editor allows you to create variables which can be used to store information. The Modify Variable Editor allows you to change existing variables and is virtually identical in looks except that it also allows you to Delete variables. The Modify Variable Editor is shown here.

Variables can be set to Number or String i.e a series of letters (This can be a ship name, weapon name, etc).

Variables must have a Name and a Default Value. You also have three optional flags that can be set.

Most variables are created in one mission but sometimes you want to store data in one mission and then access it again in a future mission. You do this by marking the variable as Persistent. Player-Persistent variables are the easiest to understand. Their value is whatever you set it to last. Even if you reload the mission they won't change. Whatever you set them to, that's their value. Campaign-Persistent variables can change their value during a mission but if you restart the mission they will reset to whatever they were at the start of the mission. The only time a Campaign-Persistent variable updates is when you move on to a new mission.

Network Variables will be transmitted to client machines during multiplayer games. Trying to send too many variables can cause lag so for this reason you are allowed to decide which variables will be marked and sent as Network Variables.

What SEXPs are there?

When the original FRED documentation was written, it listed all the SEXPs that were available to you. There is little point in doing that now though. Since the source code release the number of SEXPs available to the mission designer has been vastly increased and new ones are added every month. Instead we'll cover the the major groups and subgroups that they are organised into. You can take a good guess at what most SEXPs do simply from their name and if you can't simply add it to an event and look at the SEXP help at the bottom of the Event Editor to get much more detailed information on what it does.

Objectives

These are very simple SEXPs that test things like if a ship has been destroyed or has arrived in the mission yet.

Time

Return the time (in seconds or milliseconds) that something happened.

Logical

Sexps that deal allow you to combine SEXPs can be found here i.e check if two SEXPs are true, if one or the other is true, etc. You can also find the SEXPs to check if one number is bigger than another or to compare two names (or strings as the SEXPs call them) against each other.

Arithmetic

Various mathematical operators can be found here, allowing you to add, divide, etc the results of other SEXPs.

Status

This category is so big that it has been broken up into subcategories based on what these SEXPs test. Status basically the main category for SEXPs that check what is happening in the mission.

Change

Because this group is so large it has also been broken down into subcategories. Change is the main category for SEXPs that change what is happening in the mission.

Conditional

Before the source code was released there was only one operator in this group, when . Although still the most commonly used of all conditionals, more specialised alternatives have been added that allow you to do the same thing to multiple ships (for instance it is now possible to use a SEXP to say IF ship x,y, or z have done something DO something to the ones that have).

AI Goals

This is where you tell the AI what ships are trying to achieve.

Events / Goals

SEXPS allowing you to check if events or goals have been achieved or not.

Training

These operators were used mainly in pilot training missions in Freespace 2. However they are very useful and as such have since found lots of uses in non-training missions. Some of them return boolean values or numbers, some do not return anything.