Home/Help/State machine/Variables and conditions

STATE MACHINE

Variables and conditions

A variable is something the flow remembers: on or off, a number, a text, or a message that happens. An interaction can depend on it with an If, so the same click does one thing or another. Here a Locked switch stops the switch from turning on. The page that plays the file can set the variables too.

Do it in the editor: guided tour6 steps · about 4 minutes · opens a practice scene

Step by step

  1. Add a variable

    Click + in the right panel's Variables. Its editor opens beside the row with the name selected: type Locked and press Enter. Variables belong to their flow.

  2. Make it on or off

    In its editor, open Kind and pick On / off. The kinds are On / off, Number, Text and Message; Initial is the value it has when the flow starts.

  3. Give the click a condition

    Click the Click label on the arrow from Off to On. In its editor, click + Condition and pick Locked. Every condition must hold for the interaction to be taken.

  4. Only while it's unlocked

    Click the condition's value so it reads off: Locked is off. The arrow's label now says Click if Locked is off.

  5. Lock it

    Each row in Variables is a test control too: flip Locked's switch. It changes the value in the preview only; starting the flow again puts the initial value back.

  6. Try it

    Click the switch on the canvas: locked, nothing happens. Flip Locked off and click again: it turns on. What happened lists each change.

Good to know. Numbers compare with =, ≠, <, ≤, > and ≥, and a condition can compare with another variable ({x}). Once an interaction has an If, its When can be As soon as the If holds: it happens as soon as a variable makes the If true. A Message variable happens instead of holding a value: When › A message arrives waits for it. In an exported file the page sets, reads and sends them by name: player.set("Locked", true), player.get("Locked"), player.send("reset").

Keys

EscClose the editor
SpaceStart the preview again