- Execution starts in the main function (main is just a normal function).
- 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:
- You need a at the end of each command
- Including other files:
Format :
For example:
- Comments:
// comments out everything to the right of the // on this line only
/* */ comments out everything between the /* and the */
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:
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:
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:
or
Please see the Game Module Classes
reference for a list of scripting commands.
- 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.
- +=
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.
- <
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.
- &&
AND
- ||
OR
- !
Logical negation (true if argument to its right is false, false
otherwise).
- &
Bitwise AND a variable.
- |
bitwise OR a variable.
- &=
equivalent to x = (x & y);
- |=
equivalent to x = (x | y);
- ;
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.
|