Variables

All variables in Zoomscript are strings (default Scratch behaviour). They are stored as and treated as strings. However, during runtime and procedure calls, the value of the variables is translated to a 'pseudotype'.

A pseudotype acts as a datatype, but the variable is still, always, a string. Pseudotypes are used by procedures and runtime syntax parsing to validate data and to prepare data parsing appropriately. The following pseudotypes are supported:


  • Integer (e.g. 0, 1, 100, 10240)
  • Real (e.g. 0.01, 0.1, 0.123)
  • Boolean (e.g. true/false)
  • Character (e.g. 's', 'S')
  • String (default)


Variables must be declared before they can be used. To declare a variable, the following syntax is to be used:

Use 'var' followed by the variable name. By default, the variable value is 0.

var [varName]

As of build 20109, you can also declare multiple variables on the same line:

var [varName] [varName] [varName] ...

Variable names are case insensitive, and can only consist of letters. There are also some more guidelines to prevent code ambiguity:

In the above code, a VariableError will occur for each variable declaration and your code won't compile. Variable memory is allocated during compilation.

As expected, values of variables can be changed directly using the equals symbol (=):

Constants

To make a variable constant, it must already be declared. Initialisation is optional (default value is 0). The following syntax makes variables constant, and the values of the variable can no longer be changed:

lock [varName]

Attempting to change the value of a locked variable will result in your program crashing:

Capturing

Variables have special syntax if you want to 'capture' the returned value of a function. Instead of using the equals sign (=), use the ampersand (&) symbol. When using this symbol, Zoomscript will know that you want to capture the returned value of the function and store it in the variable.

The next tutorial is on procedures and functions where returned values will be discussed in more detail.

Increase/decrease

Variables can be increased and decreased using the [variable]++ and [variable]-- syntax.