-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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 SpindleEven 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():
- Line 480:
set()resets variables - Line 505:
executeStoryInit() - 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