Difference between revisions of "If-then-else"

From FreeSpace Wiki
Jump to: navigation, search
(Example SEXP tree: an essential piece of info)
m (Example SEXP tree: formatting)
Line 9: Line 9:
 
==Example SEXP tree==
 
==Example SEXP tree==
 
[[image:if-then-else.jpg]]
 
[[image:if-then-else.jpg]]
 +
 
In this experimental mission, Omicron departs 20 seconds into the mission.
 
In this experimental mission, Omicron departs 20 seconds into the mission.
  

Revision as of 19:51, 27 January 2011

If-then-else (Conditional operator)
	Performs one action if a condition is true (like "when"), or another action (or set of actions) if the condition is false.  Note that this sexp only completes one of its branches once the condition has been determined; it does not come back later and evaluate the other branch if the condition happens to switch truth values.

Takes 3 or more arguments...
	1:	Boolean expression to evaluate.
	2:	Actions to take if that expression becomes true.
	Rest:	Actions to take if that expression becomes false.

Example SEXP tree

If-then-else.jpg

In this experimental mission, Omicron departs 20 seconds into the mission.

Remember that if-then-else does not continually check whether its conditions are true or false. The destroyed-or-departed-delay "tells" if-then-else when to check if its condition is true or not.

If you substitute destroyed-or-departed-delay to true, then the player's shield icon will flash at mission start. If it's (has-time-elapsed 15), then the player has 15 seconds to destroy Omicron. If he manages to kill Omicron in 15 seconds, then his ETS will flash. If not, his shield icon will. If the player kills Omicron in the 16th second, his ETS gauge will not flash.