Variables serve to store and manage dynamic information during the game's execution. They can be used for a wide range of purposes, including:
In essence, variables are crucial for making games dynamic, interactive, and adaptable, allowing players to actively influence the game world and game mechanics to respond accordingly.
In Homer, you can define variables and modify their value at each step of the flow.
You have two types of variables: global variables and local variables.
This kind of variable is strongly typed and it can only store values of that type. Any attempt to assign a value of a different type will result in an error. They are stored in the project and you can manage them by accessing the “Variable panel” from the main project menu.
Global variables are always preceded by the $ and must be named without spaces or any special character.
For example:
✓ $myTextVariable or $my_text_variable
✗ $my Variable or $my+variable
If you are in a Text node ****or a Choice node variables must be surrounded by curly braces:
{$myTextVariable = “Pippo”}
Otherwise (in conditional node or Variables node) you don’t need to surround them with curly braces.
$myTextVariable = “Pippo”
In the Text or the Choice node ****nominating it without setting its value {$myTextVariable}, its value will be printed out once the flow is running.
When you type the $ character, a pop-up with the available variables will be displayed to help the variable insertion.
You can add a new global variable either introducing it in the context of the text of a node or from the Variable panel.
Once the variable has been created you can set its default value from the Variable panel.
Changing the name of the variable from the Variable panel will refactor any use of that variable in all the flows of the project.
This kind of variable is generic and its scope is confined in the running flow.
Local variables are always preceded by the % and must be named without spaces or any special character.
For example:
✓ %myVariable or %my_variable
✗ %my Variable or %my+variable
If you are in a Text node ****or a Choice node variables must be surrounded by curly braces:
{%myVariable = “My string”}
Otherwise (in conditional node or Variables node) you don’t need to surround them with curly braces.
%myVariable = “My string”
In the Text or the Choice node ****nominating it without setting its value {%myVariable} its value will be printed out once the flow is running.
Any valid operator can be used to set the variable value:
For Global Variables the value must respect the type of the variable:
✓ $myTextVariable = “My string”
✓ $myTextVariable = “My string ” + $mySecondTextVariable
✗ $myTextVariable = 12
✓ $myIntVariable = 123
✓ $myIntVariable = 123 + $mySecondIntVariable
✓ $myIntVariable ++
✗ $myIntVariable = “Abc”
For Local Variables the value can be of any type:
✓ %myVariable = “My string”
✓ %myVariable = “My string ” + $mySecondVariable
✓ %myVariable = 12
To increment the value of a variable:
✓ $myIntVariable = $myIntVariable + 1
✓ $myIntVariable ++
✗ $myIntVariable += 1 (would work only for javascript projects)
In Conditional nodes the condition expressed must always return a Boolean:
✓ $myIntVariable == 10
✓ $myIntVariable >= 10
✓ $myBoolVariable
✗ $myIntVariable = 1
Homer will parse and verify your variables and will display an alert each time the variable definition is wrong.
Table of Contents