Branching narratives.
Stories aren't always linear. Define conditional paths that respond to your data or user state.
// Branch based on a function
story.story.addBranch(
"crossroads",
(sceneData) => sceneData.sceneIndex === 0,
"northern_route"
);
// Branch based on a key-value condition
story.story.addBranch(
"northern_route",
{ key: "completed", value: true },
"finale"
);
// Listen to lifecycle events
story.story.on("sceneStart", (s) => {
console.log("Now showing:", s.id);
});
story.story.on("complete", () => {
console.log("Journey finished");
});
The Crossroads
Decision point where the narrative splits based on data conditions or user interaction state.
Northern Route
Conditional branch taken only when the predicate function returns true. Otherwise continues linearly.
The Finale
Convergence point. Branches can merge back, loop, or terminate independently.