VerseBuilderDocs

Docs/Core concepts/The WHEN / IF / DO model

The WHEN / IF / DO model

Every behavior in Verse Builder is a rule: WHEN something happens, IF a condition is true, DO these actions. That is the entire vocabulary.

Last updated 2026-06-06

Anatomy of a rule

Rules live in the Rules tab of each device. They're ordered, and every rule has the same three slots:

WHEN <event>
IF   <condition>       # optional, defaults to "always"
DO   <action 1>
     <action 2>
     ...
Rule shape — every rule has exactly one WHEN, zero or more IFs, and one or more DOs.

When the event fires, the rule first checks every IF condition; if all pass, the DO actions run top-to-bottom for the agent (player or device) that triggered the event.

WHEN — the trigger

A trigger is the event that wakes the rule up. Common ones:

  • On Begin — once, when the round starts.
  • On Player Joined — fires per player joining.
  • On Elimination — fires when one agent eliminates another.
  • On Button Pressed, On Volume Entered, On Timer Elapsed — device-specific signals.

Every event carries the agent that caused it (usually the player). Your IFs and DOs receive that agent implicitly.

IF — the gate

IF is optional. If you omit it, the rule runs every time the event fires. With one or more conditions, the rule only runs if all of them are true.

  • Is in phase — only when the game is in a given phase.
  • Compare variable — only when coins ≥ 100.
  • Has item — only when the agent holds shield_potion.

💡 Tip

Conditions are per-trigger: they re-evaluate each time the event fires. There is no “global” IF that runs continuously.

DO — the actions

Actions are the side effects. They run in the order you list them. You can mix any combination — granting items, changing variables, showing HUD messages, teleporting.

  • Increment Variable coins by 10.
  • Show HUD Message with text from a Message.
  • Activate Device on a teleporter to teleport the agent.

Patterns

Branching by phase

Two rules on the same event, gated by different phases — that's how you switch behavior between lobby and game.

Rule A: WHEN On Player Joined  IF Is in phase = lobby   DO Teleport to lobby_spawn
Rule B: WHEN On Player Joined  IF Is in phase = game    DO Teleport to game_spawn

Sequencing actions

Actions in a single DO run top to bottom. Use this to chain reward + feedback + sound on a single event.

WHEN On Elimination
DO   Increment Variable coins by 10
     Show HUD Message "+10 coins"
     Play Sound coin_pickup

Gating with a counter

Combine IF Compare variable with DO Set variable to build progression gates (level-up, unlock, …).

Gotchas

⚠️ Watch out

Order matters in DO. If you check a variable in one action and change it in the next, the next rule that reads it will see the new value. Most people don't notice — until they do.

⚠️ Watch out

No break. You can't stop a rule mid-DO. To skip actions conditionally, split into multiple rules with different IFs.

📌 Note

Each rule is independent: it doesn't share state with other rules beyond the variables it reads/writes. If you find yourself wanting to “pass data” from one rule to another, use a Variable.

What gets generated?

Each WHEN subscribes to an event on a device, runs the IF as a failable expression, and emits the DO actions inline:

# WHEN On Elimination DO Increment Variable coins by 10
EliminationManager.EliminatedEvent.Subscribe(OnElim)

OnElim(Agent:?agent):void=
    if (Raw := Agent?):
        SetCoins(Raw, GetCoins[Raw] + 10)

You don't write any of this — the Composer emits it from your rules, deterministically and the same way every time.

  1. Open any rule

    Switch to the Rules tab on any device and expand a rule. You'll see the three slots labeled WHEN / IF / DO.
  2. Peek the Verse output

    Hit ⌘ + . to peek the generated Verse code for the current device without leaving the rules editor.

See also