Variables
In variables you can store values for future use. Before using them, they have to be declared.
Declaring variables
Variables can be declared in different ways.
Local variables
In functions variables are declared using the declare
keyword, a datatype and an identifier. Local variables can be declared with an initial value. If the datatype can be derived from this initial value, the type doesn't have to be explicitly declared.
Global variables
In the global scope (alongside directives and function definitions) variables can't be declared with an initial value. Thus a explicit datatype is mandatory.
Extension variables
Variables can also be attached to existig objects and later read from these objects:
Setting a value as in the case of SomeOtherVar
will not set the value of the variable but rather the default value for reading this variable from objects that don't have this variable initialized yet.
Such variables may be aliased. This comes is necessary when you have to objects of the same type with the same variables, e.g. two players:
On top of that there are some modifiers that can be inserted between declare
and the datatype:
persistent
Persistent variables are available when revisiting the script, so you could store settings in the user object or something like cookies in a ManiaLink's Page
object and use them once the user comes back.
Note that you can only store a limited amount of data on an object.
Note that you cannot change the type of a persistent variable and have to use a new name;
netread
netwrite
Using variables
You can write to a variable by assigning a value to it:
The type of a declared variable can't change and the values have to match the variable's type.
Reading a variable is as easy as using it's name in your program:
It is also possible to use something like pointers: variables that point to certain objects.
Last updated