In the scripting interface, variables are declared in 2 ways, local and remembered.

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 how you debug a variable's value, but will only work for local variables if they are declared earlier within the same function:

print(foo); //displays "foobar"

Note that once a local variable is declared, you can change its type at any time, by re-assigning it:

foo = new Rectangle();

Remembered 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 Remembered variable:

if(foobar == "foo")
	foobar += "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, by other scripts and between game-sessions.

The one limitation of Remembered variables is that only certain types can be passed in to game.remember. This is because they will eventually need to be converted into text to be saved with the game data.

Also note that the script editor will allow you to perform the following (bad) code:

foo = new Rectangle(); //this is bad if foo is a remembered variable

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 type. We have no control over this, so just please only choose the types below when re-assigning a remembered variable.

Remembered Variable Types Edit

Name Description
Integer A whole number.
Double/Float A decimal number.
String A string of text.
Point java.awt.Point
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)

Remembered variables are also displayed in the variable list UI, which you can bring up while the game is running by pressing Ctrl+V.

Community content is available under CC-BY-SA unless otherwise noted.