Homer Doc

Homer Versions history

Homer Docs

What are variables

Variables serve to store and manage dynamic information during the game's execution. They can be used for a wide range of purposes, including:

  1. Game state storage: Variables can be used to keep track of information such as character state, player scores, current level, available resources, and so on.
  2. Game flow control: Variables can be used to control the game's behavior based on player actions or other events. For example, a variable might enable or disable specific features or events in the game.
  3. Game calculation and logic: Variables can be used to perform calculations and logical operations in the game. For example, a variable might hold the result of a mathematical operation or a logical decision based on the game state.

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.

Global 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.

variables-panel.gif

Global variable types:

Define a global variable

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.

var-popup.gif

You can add a new global variable either introducing it in the context of the text of a node or from the Variable panel.

add-variable.gif

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.

Local Variables

This kind of variable is generic and its scope is confined in the running flow.

Define a local variable

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.

General Rules

Any valid operator can be used to set the variable value:

  1. Addition (+): Adds two numbers together or concatenates two strings.
  2. Multiplication (*): Multiplies two numbers together.
  3. Division (/): Divides the first number by the second.
  4. Exponentiation (**): Raises the first number to the power of the second.
  5. Modulo (%): Returns the remainder of the division of the first number by the second.
  6. Increment (++) and Decrement (--): Increase or decrease the value of a variable by 1.

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 helps you

Homer will parse and verify your variables and will display an alert each time the variable definition is wrong.

var-verify.gif

Table of Contents