Contents Up Previous Next

Script language keywords

Data types
if, else statements
while
import
export


Data types

Type Description
char Single byte data type, can store a single character or number -128 to 127
short 16-bit integer, can store numbers from –32,768 to 32,767
int 32-bit integer, can store from –2,147,483,648 to 2,147,483,647
string Stores a string of up to 200 characters

You will normally only need to use the int and string data types. The smaller types are only useful for conserving memory if you are creating a very large number of variables.

To declare a variable, write the type followed by the variable name, then a semicolon. For example:

int my_variable;

declares a new 32-bit integer called my_variable


if, else statements

if ( expression ) {
statements1
}
[ else {
statements2
} ]

If expression is true, then statements1 are run.

If expression is not true, and there is an else clause present, then statements2 are run instead.

For example:

if (GetGlobalInt(5) == 10) {
  Display("Globalint 5 is 10.");
}
else {
  Display("Globalint 5 is not 10.");
}
In this example, the first message will be displayed if the return value from GetGlobalInt(5) is 10, and the second message will be displayed if it is not.

if statements can be nested inside else statements to produce an "else if" effect. For example:

if (GetGlobalInt(5) == 1) {
  Display("Globalint 5 is 1.");
}
else if (GetGlobalInt(5) == 2) {
  Display("Globalint 5 is 2.");
}
else {
  Display("Globalint 5 is not 1 or 2.");
}

while

while ( expression ) {
statements
}

Runs statements continuously, while expression is true.

For example:

while (character[EGO].walking != 0) {
  Wait(1);
}
will run the script Wait(1); repeatedly, as long as character[EGO].walking is not zero. Once it is zero, the while statement will exit at the end of the loop.


import

import declaration ;

Declares declaration as a variable or function which is external to the current script, but that the script needs access to it. You use this to provide your room scripts with access to parts of your global script.

For example:

import int counter;
import function add_numbers (int, int);
This imports an integer variable counter and the function add_numbers from the global script to enable the current script to call them. You normally place import statements into the script header so that all rooms can benefit from them.

In order to import the variable, it must have been exported from the global script with the export keyword.

NOTE: You MUST import external variables with the correct type. If counter was declared as a short in the global script, you MUST import it as a short, otherwise your game may crash.

NOTE: You cannot currently import string variables. Instead, you should use a global string.


export

export variable [, variable ... ] ;

Declares that variable can be exported and accessed by other scripts. You must place this at the end of your global script. You can export many variables with one export line.

For example:

export my_variable;
export counter, strength;
This exports three variables - my_variable, counter and strength.