Variables

Variables are used to store state for visual scripting.

There are two types of variables. Global variables and Entity variables.

Set variable action Sets the value of a variable.

Check variable Requirement that tests the value of a variable.

Global Variables
Global variables are created in a variable database. You can access the variable databases by pressing edit variables in the Gameplay tab of the editor. Each module has its own variable database. You can access a module database by selecting the module from the dropdown in the top left corner of the Variables dialog.

Entity Variables
Entity variables are set on individual entities. You can create entity variables on an entity by selecting the entity, pressing edit object, then press the Edit variables button. These variables can be modified or checked through visual scripting but only for entities that are in the level or dungeon currently loaded.Add variables by pressing the button for the type you want to create. The one you create will appear in the list above and then you can rename it by clicking on the name. To the bottom left there are copy and paste buttons so you can easily transfer variables from one entity to another.

Saving brain state using variables
One important use of variables is saving the brain state of an entity. Entity brains are not saved in save files but variables are. This is so that brains can be rewritten or changes can be made to fix bugs on the brain without breaking save files. In order for the brain to remember what state it was in entity variables should be used to have the brain go to the appropriate place from the starting point.

Here is a simple example of a brain that uses variables to remember where it was when a game is saved. In the above screenshot you can see the variables Sitting and Moving are created on the entity. These are bools that start as false. In the brain below the entity is either setting a path to the chair, moving to a chair, or sitting in a chair. You can see Moving and Sitting being set to true or false depending on the state the entity is in. On load the entity will go to the right state based on the variable values on the entity stored in the save file.