Skip to main content

Chapter Branch

A chapter state machine for narrative slots and multi-stage bonus games: it holds the current chapter and moves along the path you choose. Stateful maths node that also compiles to the RGS.

Chapters is an object keyed by chapter id, for example { "intro": { "next": "forest", "paytableScale": 1 }, "forest": { "next": { "left": "cave", "right": "river" } }, "cave": { "next": ["river", "intro"] }, "river": {} }; JSON text is accepted. next may be a string (one path), an object (choose by key) or an array (choose by chapter id or 0-based index; an array of one needs no choice). A chapter without next is an end. Every other field is yours and comes back verbatim on Chapter.

Do emits the current chapter without moving. The node starts at Start Key, or at the first key of Chapters when that is empty. Set Choice and fire Advance in the same update to follow the matching path; a choice that resolves to no chapter stays put and reports Changed false. Reset returns to Start Key. On the RGS, where signals are booleans for the round, reset is applied before advance.

Next Keys lists the chapter ids reachable from here, whichever form next takes; with an object next the Choice is the key (left), not the id it points to. Is End is true when no path is left, Chapter Index is the position of the current key in Chapters (-1 when it is not a chapter) and Changed is true when this call moved.

Only the current key is kept between calls. In the editor preview it lives in the node; on the RGS it rides the session's round state for identified players, so a guest session restarts at Start Key every round. A stored key that no longer exists in Chapters also falls back to the start. Seedless and deterministic: branch by chance with Feature Trigger or Wheel Spin feeding Choice.

Inputs​

Parameters​

DataDescription
Chapters (object)Chapter graph keyed by id, each with an optional next (string, object or array) plus your own fields; object or JSON text. Default {}.
Choice (string)Path to follow on Advance: the key of an object next, or a chapter id or 0-based index of an array next.
Start Key (string)Chapter to start from and to return to on Reset; empty means the first key of Chapters. Default empty.

Actions​

SignalDescription
DoRuns the node.
AdvanceMoves to the chapter that Choice resolves to; stays put when nothing matches.
ResetClears the node's state and starts again.

Outputs​

Events​

SignalDescription
DoneFires when the node has finished, on success and failure alike.

Results​

DataDescription
Chapter (object)The current chapter object with all your fields; {} when the key is not a chapter.
Current Key (string)Id of the current chapter.
Next Keys (array)Chapter ids reachable from the current chapter; empty at an end.
Is End (boolean)true when the current chapter has no paths left.
Changed (boolean)true when this call moved or reset the chapter.
Chapter Index (number)Position of the current key in Chapters; -1 when it is not a chapter.

Usage​

  1. Build Chapters with a next per chapter and the chapter's own data alongside it.
  2. Set Start Key and fire Do to emit the opening chapter.
  3. Read the chapter's fields from Chapter, or wire Current Key into Variant Selector key with one variant per chapter.
  4. Set Choice and fire Advance when the player, a Feature Trigger or a Wheel Spin picks a path.
  5. Fire Reset to start the story over.
note

State persists across rounds for identified players only. A guest session starts fresh every round, so a guest restarts at Start Key on every request.