Closed david-donachie closed 1 year ago
A <<link>>
's passage forwarding is always executed after the contents of the link.
In other words, the following:
<<link "» Back" "Start">>
<<if $ended>>
<<run Engine.restart()>>
<</if>>
<</link>>
Is functionally equivalent to:
<<link "» Back">>
<<if $ended>>
<<run Engine.restart()>>
<</if>>
<<goto "Start">>
<</link>>
The critical part being:
<<run Engine.restart()>>
<<goto "Start">>
That's a race condition within SugarCube itself. Worse, Engine.restart()
calls for the reload of the window/tab as its final act. Thus, the race condition becomes some bizarre combination of SugarCube and browser engine race.
In essence, play stupid games with the engine, win stupid prizes.
Describe the bug.
Running
Engine.restart()
inside a link with a destination, does not correctly run StoryInit. StoryInit is run, but the state is overwritten. Any variables set inside StoryInit are undefined.To Reproduce:
Set some variable in StoryInit
And reference it in your Start passage
Make a link like the following:
If you click the link the game restarts, but $test is undefined, and the reference to
$test.started
throws an error.Expected behaviour.
The game should restart as normal, either ignoring the destination given, or navigating to it after the StoryInit is run. In either case, variables set in StoryInit should be defined as normal.
Additional Info
Courtesy of @fg109 on the Twine Discord it looks like this may be a race condition. I'll quote his notes in full.
I'll note that the example above may seem contrived (i.e. why have a destination and a restart()). My actual use case was:
Project details.