Skip to main content

Variables

Variables are named data containers that persist throughout a playthrough of your visual novel. They drive conditions, track reader choices, manage inventory, control branching, and personalize text.

Variable Types

Nongine supports four variable types:

TypeDefault ValueUse Cases
booleanfalseFlags: hasKey, metAlice, doorUnlocked
number0Scores, counters, stats: affinity, hp, gold
string"" (empty)Names, selections: playerName, currentRoute
item0Inventory items with quantities: potionCount, keyFragment

Creating Variables

There are two ways to create variables:

In the Inspector

Open the Variables section in the Inspector panel (accessible from the sidebar). Click "New Variable" and provide:

  • Name — Must be unique. Use descriptive camelCase names (e.g., playerName, hasSword, affinityLuna).
  • Type — boolean, number, string, or item.
  • Default value — The value at the start of a new playthrough.

Inline from VariablePicker

Anywhere you see a variable dropdown (in Condition nodes, SetVariable nodes, Choice options, etc.), there is a + button. Click it to create a new variable on the spot without leaving the current panel.

The SetVariable Node

The SetVariable node modifies one or more variables when execution passes through it. It has one input and one output handle. In the Inspector, you configure a list of actions, each with:

  • Variable — Which variable to modify.
  • Operation — What to do:
    • set — Set to a specific value.
    • toggle — Flip a boolean (true becomes false, false becomes true).
    • increment — Add a value to a number variable.
    • decrement — Subtract a value from a number variable.
    • reset — Reset to the variable's default value.
  • Value — The value to set, add, or subtract (not needed for toggle and reset).

Multiple actions can be configured on a single SetVariable node. All actions execute simultaneously when the node runs.

The Script Node

For advanced logic beyond what SetVariable offers, the Script node executes custom JavaScript code. Scripts have access to the project's variables and can read and modify them programmatically. This is useful for complex calculations, string manipulation, random number generation, or any logic that would be cumbersome to express with multiple nodes.

Variable Interpolation

Reference a variable's value in any text field by wrapping an expression in curly braces:

  • Simple reference: {playerName} — Displays the value of the variable.
  • Arithmetic: {score * 2} — Evaluates the expression.
  • Conditional: {hp > 50 ? "healthy" : "hurt"} — Ternary expressions.

Interpolation works in:

  • Dialog text
  • Narration text
  • Choice option labels
  • Choice prompts
  • Notification text
  • Character name overrides

If a referenced variable does not exist, the raw token (including braces) is displayed, which helps you catch typos during testing.

Using Variables with Conditions

Variables and Condition nodes work together to create adaptive narratives. The condition system supports:

  • Simple conditions — Variable + operator (==, !=, >, <, >=, <=) + value.
  • Compound conditions — Multiple clauses combined with AND / OR logic, with nesting.

Conditions appear in three places:

  • Condition nodes — Route execution to "true" or "false" output handles.
  • Choice option conditions — Control which options are available or visible.
  • Sequence step conditions — Make individual steps within a sequence conditional.

Example Pattern

  1. A Choice node presents "Take the sword" and "Leave it."
  2. The "Take the sword" option has a SetVar action: hasSword = true.
  3. Later, a Condition node checks hasSword == true.
  4. True: the reader uses the sword in combat. False: the reader must find another solution.

Item System

The item variable type is designed for inventory management:

  • Add Item steps in Sequences (slash command /add_item) increase an item variable's quantity.
  • Remove Item steps (slash command /remove_item) decrease it.
  • Both steps specify the item variable and a quantity (default 1).
  • When an item is added, a notification can be shown to the player.
  • Item variables can be checked in conditions just like number variables (e.g., potionCount > 0).

HUD Display

Variables can be displayed on screen during gameplay using the HUD (Heads-Up Display) system. HUD elements are configured per-variable and support three display types:

TypeDescription
barA progress bar (e.g., health bar). Requires a maxValue.
numberA numeric display (e.g., "Gold: 150").
icon-textAn icon next to a text value (e.g., a heart icon with the HP number).

Each HUD element has:

  • Variable — Which variable's value to display.
  • Label — Display label.
  • Color — Visual color of the element.
  • Positiontop-left, top-right, bottom-left, or bottom-right.
  • Visible — Toggle whether it is currently shown.

HUD elements update in real time as variable values change during playback.

Debugging Variables

During playback in the editor's preview mode, you can monitor all variables and their current values in real time. This is invaluable for testing branching logic and verifying that variables are being set correctly as you play through different paths.