Skip to content

Variables and Logic

M. H. Golkar edited this page Oct 9, 2022 · 4 revisions

Arrow comes with rich sets of features that make it a very useful tool for production of text-heavy games (e.g. adventures, RPGs, etc.) besides design and development of interactive narratives.

Variables and nodes such as User-Input, Variable-Update, Condition, etc., are some of these features, helping developers to introduce logic to their projects, with no coding.

In this document, we review some of these features.

For more information check out respective documentations. Also browse documentation on Characters and their tags for other interesting possibilities.

Basics

There are three kinds of variables in Arrow:

  • Numbers (num) which hold an integer
  • Booleans (bool) which hold a binary state (i.e. True or False)
  • Strings (str) which hold text

Variables in Arrow are global to the document, so every scene and node can access to their value.

To create a variable switch to the respective tab in the Inspector panel.

You may need to use arrow buttons on the top-right corner of the panel to move the tab into view.

You can create and modify initial value of any variable there, but remember, to keep changes, you need to press the set button.

Variable Modification

We can modify current value of any variable in runtime, using modifier nodes:

  • User-Input nodes show customizable prompt messages and input controls (with validation), then replace current value of their target variable with the input they receive from the player.

  • Variable-Update nodes modify current value of their target variable. Any variable type has its own set of operations and type-casting is not supported.
    Some operations accept another variable as the right-hand side of the formula; in that case if you select the same variable, the initial value of the variable will be used as rhs.

  • Generator nodes can create and set value for any variable in the runtime. There are different methods for value generation, depending on the target variable's type. Each of these methods has a set of editable options/rules that define how the value is created. For example, an integer can be made randomly from a range and may be limited to odd or even numbers.

Variable Exposure (Parsing)

To expose a variable in textual node-types including Dialog, Interaction, Content, etc. use the variable's name in curly brackets (i.e. a mustache placeholder resembling {variable_name}). When such nodes are being played, the Arrow console and any compatible runtime will replace them with current value of the variable.

In other words:

Hi {HERO_NAME}!
I'm RxD{ROBOT_CODE}, your robotic guide.

will be translated to following, if current value of HERO_NAME (str) is Luke and ROBOT_CODE (num) is 7 :

Hi Luke!
I'm RxD7, your robotic guide.

You can generally use any name or convention for your variables, though editor may modify it a little, replacing some characters to make it exposure safe (i.e. removing curly brackets, dots, etc.)

Thanks to Continuum Safety under the hood, if you rename a variable, Arrow revises all its exposures for you automatically.

Condition Nodes

Condition nodes compare current value of their target variables

  • to a specified value,
  • to current value of another variable
  • or to the initial value of the variable itself

in runtime.

Condition nodes compare current state of their target variables using type-specific operators. For example a number can be checked if it's lesser or equal to another number, while strings can be checked for their length or matching a pattern. In other words, type-casting is not supported so you can't compare numbers to strings or booleans (e.g. 0 can't be compared with false.)

Usage

Adding logic to your Arrow adventures, can advance them to higher levels of interactivity. Yet you may not need Variables and their modifiers or check nodes everywhere.

Recommended approach is to use Arrow's navigation features to control sequences of events, as much as possible. These features are much easier to use and maintain, and are much more performant.

Take advantage of logic when the story needs to control some values such as inventory, score, etc. For example, you can define HP (health points) variables for your players or characters and update them after each combat; then you may use Condition nodes to see whether they are still alive (i.e. HP > 0) or you need to Jump the player to the afterlife scene and resurrect them!

Quick Tip!
If you intend to check a variable many times in your story, or need a repeatable block of logic, create a Macro and reuse it as many times as you like via Macro-Use nodes.

See also:

  • Characters and their Tags

    For another interesting way to introduce logic.