Small Logo

Slow Glass Variables

The Slow Glass scripting language supports the use of variables to contain changing information.

Variables are included in scripts by prefixing the name with a dollar sign ($). Names can be any combination of letters and underscore characters. If you want to “isolate” the name from other content on the line you can surround the name with curly braces { }.

echo $my_var ${my_var}suffix

Understanding Variables

It is best not to think of variables as just “something to hold a value” (which is what most programming languages require). In Slow Glass a variable acts more like a “macro” in that the text content of the variable is inserted into the command, which will then be executed.

Hence variables don’t have “types” as such, they just hold text that will be inserted into the current command and the command processor itself will interpret the text as a number, variable name or whatever.

Indeed you can put an entire command into a variable (if you seriously want to confuse yourself). Consider:

make command be log hello world

$command

These two lines are a roundabout way of printing “hello world” to the console.

Finally note that variables are expanded into text before any expressions are evaluated, variables are NOT handled by the expression evaluator, which will just see the text content of the variable.

Creating Variables

You define variables with the let or make command

(let | make) {variable-name} [be] {value...}

This will create (or overwrite) a variable with the given name and set the value to the remaining content of the line (including any spaces).

You can also assign multiple variables at the same time with the command:

assign {variable-name1} {variable-name2}... as {value1} {value2}...

This is useful to save space for multiple assignments but can also be combined with the built-in variable *PARAMETERS* which can be passed to a scene with the start command, for example:

start traffic 50 medium

Will cause the variable *$PARAMETERS* within the scene named “traffic” to have the value:

50 medium

You can assign these values to variables like this:

assign density volume as $PARAMETERS

and *$density* will be 50 and *$volume* will be ‘medium’.

You can randomly assign values from a list provided:

choose {variable-name} [from] {list...}

This will create (or overwrite) a variable with the given name and set the value randomly to one of the items from the space-separated list.

You can also select all items from a list that contain a given word:

match {variable-name} to {search-word} [at (start|end)] from {list...}

This will create (or overwrite) a variable with the given name and set the value to the matching items from the space-separated list, joined back together with spaces. If there are no matches then the value will be set to the default “not found” value.

Updating Variables

The same command will update variable values, but remember that the $ symbol will cause the value to be used, NOT the name, so to update a value use a structure like:

let my_var be 1

let my_var be ($my_var + 10)

The content in round brackets will be assumed to be an expression and will be replaced by its evaluated result - see LINK NEEDED.

There are also convenience functions provided for common operations:

(increment | decrement) {variable-name}

Which will increase or decrease the variable provided it looks like a number.

Variable Expansion

Variables are expanded (i.e. replaced by their value) when it most makes “sense” to do so. In general:

The Data Scene

If you create a scene called “data” it will be handled specially. You do not need to start the scene, it will be started for you automatically.

Although you can do anything with this scene I recommend that you only use the *setup* or *begin* cues to create user variables.

These variables will be available to all other scenes, effectively becoming global variables.

A local variable with the same name will take priority and “hide” the global variable but if necessary you can still access the global variable with the construction:

${data:variable-name}

This scene is useful place to put large array initialisations, keeping them out of the way of the actual commands.

 

Introduction

Up Level

Built-in Variables

Next