Difference between revisions of "If-then-else"
m (→Example SEXP tree: formatting) |
Goober5000 (talk | contribs) (elaboration and clarification) |
||
Line 12: | Line 12: | ||
In this experimental mission, Omicron departs 20 seconds into the mission. | In this experimental mission, Omicron departs 20 seconds into the mission. | ||
− | + | ''If-then-else'' is equivalent to a ''when X'' paired with a ''when not-X'', for the same X. Thus if ''if-then-else'' appears in an event by itself, one of its branches will immediately fire. Therefore, this sexp will probably be more useful when chained after, or used as a subordinate to, a controlling sexp. In the example above, the ''destroyed-or-departed-delay'' sexp controls when ''if-then-else'' should check if its condition is true or not. | |
− | If you substitute ''destroyed-or-departed-delay'' | + | If you substitute ''destroyed-or-departed-delay'' with ''true'', then the player's shield icon will flash at mission start. If you substitute it with (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. |
[[Category:SCP SEXPs]] | [[Category:SCP SEXPs]] |
Revision as of 06:10, 29 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
In this experimental mission, Omicron departs 20 seconds into the mission.
If-then-else is equivalent to a when X paired with a when not-X, for the same X. Thus if if-then-else appears in an event by itself, one of its branches will immediately fire. Therefore, this sexp will probably be more useful when chained after, or used as a subordinate to, a controlling sexp. In the example above, the destroyed-or-departed-delay sexp controls when if-then-else should check if its condition is true or not.
If you substitute destroyed-or-departed-delay with true, then the player's shield icon will flash at mission start. If you substitute it with (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.