In the scripting interface, variables are declared in 2 ways, local and long-term.
Local Variables Edit
The following code demonstrates how to create, query and then modify a Local variable:
var foo = "foo"; if(foo == "foo") foo += "bar";
The following code is the recommended method of identifying variable's values, but will only work for local variables if they are declared earlier within the same function:
print(foo); //displays "foobar"
Long-Term Variables Edit
Not only are these kind of variables Global, but they will also be saved and loaded automatically with a save-game. This is very important when you need to maintain quest states, or anything else that need to be retained between game sessions.
The following code demonstrates how to create, query and then modify a Long-Term variable:
self.remember("foo","foo"); if(foo == "foo") foo += "bar";
Note that after the initial long-winded declaration, the code remains the same, except that foo will now be able to be referenced and queried outside the function, even by other scripts.
The one limitation of Long-Term variables is that only certain types can be passed in to self.remember. This is because they will eventually need to be converted into text for saving/loading.
Also note that the script editor will allow you to perform the following (bad) code:
foo = new Rectangle();
After the above code is executed, the engine will continue to work fine while the game session is running, but it will not save correctly because the type that the variable has changed into is not registered by the engine as a known SaveReferenceable.
Long-Term Variable Types Edit
|Integer||A whole number.|
|Double/Float||A decimal number.|
|String||A string of text.|
|HexagonPoint||The engine's logical coordinate object. Also allowed are FinalPoint and TilePoint.|
|Entity||Any entity on the map can be saved. If the entity is dead, the reference will be lost.|
|(More to come)|