Variables are some piece of data that can be referenced in the context of your script. There are two basic uses for variables:

Creating Variables

To create a variable, select your script in the Scripts Panel and go to the Inspector, then press the ‘+’ button. From there, with the list expanded, you will most typically want to:

  1. Add a custom name for your variable

  2. Select the type of data it represents

  3. Optionally expose it

  4. Optionally have it synced

    A  variable created in the script’s Inspector view and exposed to be linked to an object instance in the world that has this behavior.

    A TriggerTool variable created in the script’s Inspector view and exposed to be linked to an object instance in the world that has this behavior.

Exposing a variable allows it to be modified for any instance of its script. This allows you to deploy multiple instances of a script and hook each one up to different values, allowing you to reuse one script definition to trigger similar logic in different applications.

For example, your script might expose a variable for a button and a variable for a door. You could place two instances of the same script into the world and hook them up to different object instances to make two different openable doors anywhere on the island, all with one simple script.

Syncing a variable allows its value to be updated as it changes across both clients and servers. Generally should only be used for variables that you are changing during script runtime and that need to be reacted to on clients. Otherwise probably not needed, most variables won’t need to be synced.

Hooking Up Variables

Once a variable is created in your script, you can assign values to those variables in instances of that script:

  1. Navigate to the variable overrides UI.

    For playground games, your exposed variables appear in the settings for that game.

    A Trigger Zone used as a goal in a playground game. The object instance is linked to the variable in the game’s settings.

    A Trigger Zone used as a goal in a playground game. The object instance is linked to the variable in the game’s settings.

    For other scripts placed in the world, variables appear when you “edit” the script instance by either scanning it and pressing ‘E’ or selecting it in build mode and pressing ‘E’.

    A Trigger Zone hooked up to a script. The object instance is linked to the variable in a script instance that was placed through the build menu.

    A Trigger Zone hooked up to a script. The object instance is linked to the variable in a script instance that was placed through the build menu.

  2. Select an object, behavior, or value to reference.

    In the Variable Override panel, a selector will exist to choose the value of the variable for the selected script instance. The nature of this selector depends on the type of the variable.

    For objects, the selector will pop up a searchable context menu with a list of all objects that match the data type or have a behavior that does. Entries in this list include an object instance name and a UUID for each match. You can rename object instances with custom names by entering the same “edit” mode on them in order to assist with finding them in the list.

Scripting with Variables

After adding a variable to your script (and before or after hooking it up), some variable nodes will appear in the node menu.