Skip to content

No event fired after Story.restart() or Story.storage.clearGameData() #115

@rohal12

Description

@rohal12

Description

When Story.restart() runs (directly or via clearGameData/clearAllData), all story variables are reset to StoryVariables defaults and navigation goes to the start passage. However, no navigate event fires — the only events are variableChanged for each reset variable.

Games with external state engines (e.g., a TypeScript game engine that syncs data to Spindle variables via Story.set()) need to re-push their state after a restart. Currently there's no reliable way to detect that a restart happened.

Update: storyinit event added in v0.37.0 but Story.set() calls are overwritten

The storyinit event fires correctly after restart. However, calling Story.set() inside the storyinit callback (or even deferred via setTimeout(0)) does not persist — the values are immediately overwritten back to the StoryVariables defaults.

Reproduction

Story.on('storyinit', () => {
  // This runs, but the data doesn't stick
  Story.set('npcList', [{ id: 'test', name: 'Test' }]);
  console.log(Story.get('npcList').length); // 1 — set worked
});

Story.storage.clearGameData();
// ... 2 seconds later:
// Story.get('npcList').length === 0 — overwritten by Spindle

Even with setTimeout(() => Story.set(...), 0) the data is overwritten.

But calling Story.set() manually from the browser console 1+ seconds after clearGameData DOES persist. So there's a specific window where Spindle resets state after the storyinit event.

Expected Behavior

Story.set() calls made inside the storyinit callback should persist and not be overwritten by the restart's variable reset. The callback should fire after ALL state resets are complete.

Possible Cause

In store.ts restart():

  1. Line 480: set() resets variables
  2. Line 505: executeStoryInit()
  3. Line 506: bumpInitCount() — triggers storyinit listeners

But the async startNewPlaythrough() at line 500 may trigger additional state updates via .then() that overwrite variables after the storyinit callback runs.

Environment

  • Spindle v0.37.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions