Script Statements

Home
open restricted
Statements:

IF/ELSE/ENDIF FOR loop LIST loop WHILE loop BREAK/END GOTOLINE


if not ! ifcheck
or not ! ifcheck
and not ! ifcheck
...
else
...
endif

The most basic decision making statement available, and often the only one you can really use as most are loops. They can be anywhere from simple single checks to a slew of compounded checks.

Obviously, the first thing needed is the if keyword itself. After that, you have a choice to make. Depending on how you structure the checks, you might need to use the special not keyword. What that does is negate the following check such that what would've been true would evaluate to false and vice versa.

You might notice the ! and wonder what that does. Well, that is another form of the not keyword. It does the same thing, so not ifcheck is the same thing as !ifcheck. And for the non-observant ones, doing not ! will just cancel each other out.

Subsequent clauses may be added using the or or and keywords. Unlike most or/and checks in programming languages, this does not short circuit, in that it does not terminate evaluation when the condition reaches point that causes the entire condition to be true (for or) or false (for and). Instead, every check is executed. Future revisions may change this.

As far as the ifchecks, those can be found in their entirety with explanations on their use on this page.

If the overall value of the ifcheck conditions results in true, the commands immediately following the ifchecks conditions are executed, until a corresponding else or endif, or end of script, is encountered. If the value results in false, execution skips to a corresponding else. Should it find an endif instead, the execution continues after the endif.

Back to Top

for label variable start stop increment
...
exitfor label
...
endfor label

The first of three loops, the for loop is a counting loop. It looks, first, for a unique label to name the construct. Then, it gets the variable name for storing the loop value. This variable is then referenced in the loop to perform any desired actions. Next are three integer values that control the loop itself. Any or all can be expression expansions, but are computed at the start of the loop. Depending on the sign of the increment, the loop will continue until the current value is greater than stop (if increment > 0) or is less than stop (if increment < 0). An increment of 0 will prevent the loop from executing.

The endfor statement takes the label used in the corresponding for loop header to mark the end of the loop. This command will loop back to the loop header, incrementing the current value and determines if it can continue. Once the stop condition has been reached, execution skips to the first statement after the endfor.

Exitfor is used to break out of the loop.

Back to Top

list label variable list-entity
...
exitlist label
...
endlist label

The second loop is used to iterate through a list of entities. Currently, there are only three types of lists available (mobiles, objects and tokens) plus a pseudo-list (exits). Lists are iterated until all elements have been exhausted. Exits are iterated only until southwest has been processed; it does not loop around to check all exits.

The statement looks for a unique label to name the loop, then a variable name to store the list entry followed by the list entity. Execution of the loop continues until the last element is processed, or if the list is empty.

Endlist marks the end of the loop, operating just like endfor. The same goes for exitlist.

Back to Top

while label not ! ifcheck
or not ! ifcheck
and not ! ifcheck
...
exitwhile label
...
endwhile label

The while loop statement is the third and final loop thus far. It boils down to an ifcheck loop. As with all loops, the first thing needed is a unique label. After this, treat the command as if it were an if statement. You provide an ifcheck block with any optional or/and clauses.

The endwhile statement takes the label used in the corresponding while statement to mark the end of the loop. This command will loop back to the first line of the ifcheck block, as one would expect.

The exitwhile is used to terminate execution of the labeled loop, regardless how nested the script is with loops. This is a bit more powerful than the break statement found in C/C++ in that the script could be 10 loops deep and this command could exit out of the top level loop. To do that in C/C++ would require the goto statement or convoluted loop controls.

Back to Top

break return-value
end return-value

Used to terminate execution of a script. When given with no return value, the command returns the default value of 1. The return value can only be non-negative, as negative values are reserved for internal error codes. A return value converts a script into a function instead of just a called set of commands.

One interesting aspect of return values is in the trigger code. Should the overall return value of all scripts executed be 0, this will cause all calling functions that care about whether a trigger fired to believe nothing executed, even if 50 scripts ran.

The overall concept is a "lock" script. If all executed scripts return a 0, normal actions the game code would do get performed. Should any script return a non-zero value, the normal actions are bypassed. What does this do? Well, for one, returning a 0 on all triggered exit scripts will allow the game to continue with the remaining exit code, thus alleviating the need for transfers JUST to allow passage.

Note: Both commands are identical, just with two names for no real reason.

Back to Top

gotoline line

Jumps to the effective code line, not necessarily real line. Comments and blank lines are ignored. The line can be a constant or an expression expansion. The birth of this command predated any loop statements. This can create very crude loops.

The reason for the restriction is the ease at which this command can cause an infinite loop or do things that are unstable.

Back to Top

All constructs that require labels must follow a few rules:

All names must be a single word. What they are is entirely arbitrary.

Names within a single script must be unique across the entire script. The names are converted into indices for faster processing during execution.

Only 256 named labels can be used. Trust me when I say, that is alot of scripting. You will likely run out of string space available for the script before running out of labels.

A label may only be used by one construct, hence the uniqueness.
Back to Top

Back to Top