Expert

State Variables & Advanced Conditions

EXP 1  •  12 min read
What you'll learn
  • Define and configure custom state variables
  • Set and increment state from event actions
  • Write state-based conditions
  • Implement the one-time intro pattern
  • Build counter-based multi-step locks
  • Use the State Changed trigger efficiently
  • Understand persisted state and save data
1

What Are State Variables?

State variables are named key-value pairs stored in the game's runtime memory. Think of them as tracking flags or counters:

  • intro_shown = true
  • lights_on = false
  • levers_pulled = 2

They let you track game progress far beyond the simple "has item" or "puzzle solved" conditions. With state variables you can build multi-step sequences, one-time events, conditional story branches, and cumulative counter puzzles — all without writing any code.

2

Defining State Variables

Navigate to Game Settings Panel → State Variables section. Click "Add Variable". Fill in three fields:

  • Name / ID — A unique identifier, no spaces. Use underscores: lights_on, intro_shown, levers_pulled.
  • Type — Choose Boolean (true/false) for on/off flags, or Number (integer) for counters.
  • Default Value — The value when the game first starts. Boolean defaults to false; Number defaults to 0.

You can add as many variables as your game needs. They live in Game Settings, not inside any specific scene or object.

3

Setting State in Events

Two actions in the event action list modify state:

  • Set State Variable — Choose a variable, then choose a new absolute value. For booleans: true or false. For numbers: any integer.
  • Increment State Variable — Choose a number variable and an increment amount. Use positive numbers to count up, negative to count down. Example: each time the player pulls a lever, increment levers_pulled by +1.

These actions can be combined with any trigger — a click, a scene entry, a puzzle solve, a timer — giving you full flexibility over when state changes.

4

Checking State in Conditions

When building conditions on an event, the state condition types are:

  • State Equals — Variable matches an exact value. Example: lights_on equals true.
  • State Greater Than — Number variable exceeds a threshold. Example: levers_pulled > 2.
  • State Less Than — Number variable is below a threshold. Example: levers_pulled < 3.

Conditions can be combined with AND logic — all conditions must pass for the event's actions to fire. Use this to build precise, multi-requirement triggers.

5

One-Time Events (Intro Pattern)

A very common need: show an introductory dialogue the first time a player enters a scene, but never again on subsequent visits.

Setup:

  1. Create a Boolean variable: intro_A_shown, default false
  2. Create an event on the scene:
    • Trigger: Scene Entered
    • Condition: State Equals — intro_A_shown = false
    • Actions:
      1. Show Dialogue "You wake up in a strange room."
      2. Set State Variable — intro_A_shown = true

On first entry, the condition passes, dialogue fires, and the flag is set to true. On every subsequent entry, the condition fails immediately — nothing happens.

6

Multi-Step Lock (Counter Pattern)

A door that only opens after exactly 3 buttons have been pressed:

Variable: buttons_pressed (Number, default 0)

Event per button (repeat for button1, button2, button3):

  • Trigger: Object Click "buttonX"
  • Conditions: none
  • Actions: [Increment buttons_pressed +1, Hide Object "buttonX"]

Unlock event:

  • Trigger: State Changed — buttons_pressed
  • Condition: State Greater Than — buttons_pressed ≥ 3
  • Actions: [Show Object "door_open", Hide Object "door_closed", Show Dialogue "The door slides open!"]

Each button press increments the counter and hides that button. Once all three are pressed, the unlock event fires automatically.

Increment State Variable action row

Increment State Variable — add +1 each time a button is pressed.

7

State Changed Trigger

The State Changed trigger fires whenever a specific state variable's value changes — regardless of what caused the change. This is more efficient and cleaner than checking state inside every click event.

Use it as a centralized "reactor" that watches a counter and responds when it hits a meaningful value. Because it only fires on change, it does not run constantly — there is no performance concern with many State Changed events.

You can have multiple State Changed events on the same variable with different conditions: one that fires at ≥1 (partial progress feedback), one at ≥3 (unlock), etc.

8

Persisted State

All state variables are included in the game's save file. If a player quits midway and returns later, every variable value is restored exactly as it was when they left.

Design variables to be meaningful as saved data:

  • Good: chest_opened, key_collected, scene_2_intro_seen
  • Avoid using state for purely visual or temporary effects that reset when a scene reloads anyway
Tip: Keep variable names short and consistent. Use underscore prefixes for area-scoped variables in large games: kitchen_oven_on, lab_power_on, vault_code_entered.
Warning: State variable names are case-sensitive. lights_on and Lights_On are two completely separate variables. Stick to lowercase with underscores to avoid accidents.
Try it: Build a 3-switch puzzle where all three switches must be flipped ON before a locked box becomes visible. Use a counter variable switches_on, increment on each switch click, and use a State Changed trigger with condition ≥ 3 to reveal the box.