Mod:Creation Kit/Statement Reference

A statement is an arrangement of expressions used to perform work (and may just be a simple expression). There are also some more complicated statements like "if" and "while".

Define Statement


A define statement defines a single variable and, optionally, initializes it to a value. If a value is not given to it, it starts with the standard default value. A variable defined inside a function does not conflict with a variable defined in another function. A variable defined in an if or while block will not conflict with a variable defined in another if or while block that is not a child or a parent of the block that defined it.

Examples
int var float seconds = CurrentTimeInMinutes * 60.0f
 * Create an integer variable named var that starts with the default value of 0
 * Create a float variable name seconds that starts with a default value

Assign Statement
( '+=' ) | ( '-=' ) | ( '*=' ) | ( '/=' ) | ( '%=' )          ::= ([ '.'] ) ( '[' ']')

An assignment statement calculates the results of the expression to the left of the assignment operator, and variable referred to by the l-value, and either assigns the result to the l-value, or modifies the l-value by the result.

Examples
x = 5 MyObject.MyProperty += CoolFunction * 10
 * Assign 5 to x
 * Increment the property by the calculated value

Return Statement
'Return' [ ]

The return statement immediately stops running the function, calculates the result of the expression (if it exists), and returns it to the caller. The type the expression resolves to must match the return type of the function. If the function has no return type, then just use a return statement with no expression. If a function with a return type exits without a return statement, then None will be return (and a warning printed by the game if None is not allowed to be assigned to the return type)

Examples
Return 5 Return x = 5 ; This never runs, because execution has exited this function
 * Assuming the return type is int, return the value to the caller
 * Return immediately, returning nothing

If Statement
*                   ['elseif' *]*                   ['else' *]                   'endIf'

The if statement calculates its expression and, if the result is true, runs the statements underneath it until it runs into an "elseif", "else", or "endif". If the expression's result is false, then it jumps down the if, checking each "elseif" as well until it hits an "else" (which then runs its statements) or an "endif". At each "elseif" encountered, it will check the expression and, if true, run the statements under it and if false, will jump to the next "elseif", "else", or "endIf".

Examples
if value x = 1 endIf if myCoolValue == 20 x = 5 else x = 10 endIf if value > 10 x = 1 elseif value < 10 x = -1 else x = 0 endIf
 * If value is true, will set x to 1, otherwise it will do nothing
 * If myCoolValue is 20, will set x to 5, otherwise it will set it to 10
 * If the value is above 10 it will set x to 1, if it is below 10 it will set x to -1, otherwise it will set x to 0

While Statement
'while' * 'endWhile'

The while statement is a loop and will repeatedly execute the statements inside it until the expression is false.

Examples
x = 0 while x < 10 DoCoolStuff x += 1 endWhile
 * Loop until x is 10