scripting syntax

General rules

  1. Execution starts in the main function (main is just a normal function).

  2. A function must be declared before it is used:
    This means either the entire function has to be located before any calls to it or you have to add a function declaration for it (preferably at the top of the file). A function declaration is just the header part with a semicolon at the end.

    For example: set_fade_color( int color );

  3. You need a ; at the end of each command

  4. Including other files:
    Format : #include “filename”
    For example: #include “scripts/utils.scr”

  5. Comments:
    // comments out everything to the right of the // on this line only
    /* */ comments out everything between the /* and the */

Functions

All functions adhere to this general format:

For example:

The function declaration for the above example would be as follows:

There are two ways to call a function:

  • function();
    This calls the function and stops execution of the calling function until the called function returns.

  • thread function();
    This calls the function with a new thread so that the calling function/thread can keep going.

Calling format:

The number of parameters is determined by the function declaration. Functions can return values.

For example:

Entities

Map entities are referenced like this:

For example:

Only use the dollar sign ($) if the referenced entity is a map entity. If you are using a normal entity variable don’t use the dollar sign.

It is possible to get a variable for an entity if you know the name of it as follows:

Basic language commands

while
Loops until the while condition equals 0 or false. This is checked at beginning of each loop.

Format:

For example:

do/while
Loops until the while condition equals 0 or false. This is checked at end of each loop.

Format:

For example:

for
This looping construct executes until condition is false.

Format:

The init commands are evaluated just once, usually to initialize variables. Then the condition is evaluated - if it is false, the statement terminates, and if it is true, the statement executes. After that, the per loop commands are executed and the loop starts over.

For example:

if/else
This loop executes a block of commands if the condition is true. If false it executes the block of commands after the else (else part is optional).

Format:

For Example:

return
Returns from the current function/thread and optionally returns a value.

Format:

return; or
return value;

scripting commands

Please see the Game Module Classes reference for a list of scripting commands.

Variable types available

  • float - a floating-point number.
  • vector - composed of 3 floating point numbers, written as 'x y z'.
  • entity - an entity that exists in the game.
  • string - a string, written as "characters".
  • void - no return type.

Math operators

  • +=
    Equivalent to x = x + y; (works for strings as well)

  • -=
    Equivalent to x = x - y;

  • *=
    Equivalent to x = x * y;

  • /=
    Equivalent to x = x / y;

  • ++
    Increments variable by one.

  • --
    Decrements variable by one.

  • *
    Multiplication.

  • /
    Division.

  • -
    Subtraction.

  • +
    Addition (works for strings as well).

  • =
    Sets variable equal to.

Comparison operators

  • <
    Tests if less than.

  • >
    Tests if greater than.

  • <=
    Tests if less than or equal.

  • >=
    Tests if greater than or equal.

  • ==
    Tests if equal.

  • !=
    Test if not equal.

Logic operators

  • &&
    AND

  • ||
    OR

  • !
    Logical negation (true if argument to its right is false, false otherwise).

Bit operators

  • &
    Bitwise AND a variable.

  • |
    bitwise OR a variable.

  • &=
    equivalent to x = (x & y);

  • |=
    equivalent to x = (x | y);

Format operators

  • ;
    All statements must end in this.

  • ,
    Used to separate function arguments.

  • (
    Opening for a function call, grouping for mathematical functions.

  • )
    Closing for a function call, grouping for mathematical functions.
  • #
    Prefix for #include and #define.

  • ...

  • .

  • [
    Opening for array index.

  • ]
    Closing for array index.

  • {
    Opening for a block of statements.

  • }
    Closing for a block of statements.