For my project, I need to be able to direct the reader to any passage from the initial URL, so I have implemented a URL query that sets the startPassage config setting, redirecting to the chosen passage. E.g., "index.html?nav=My%20Passage" would trigger a change in the
This seems to work fine, until you also disable history controls so that the reader cannot use the browser's back/forward buttons to navigate through the story history. At that point, if you open a second instance of the story in the same window using a different startpoint, then press the browser button to go back to the first instance, SugarCube/Twine can't cope, triggering an error an error on Object.History, e.g.:
[quote]Error: Uncaught TypeError: Cannot read property 'title' of undefined.
Stack Trace:
TypeError: Cannot read property 'title' of undefined
at Object.History.restore (file://localhost/Twine/Tests/Test.html:82:7806)
at Object.History.init (file://localhost/Twine/Tests/Test.html:82:2963)
at HTMLDocument.<anonymous> (file://localhost/Twine/Tests/Test.html:81:17642)
at j (file://localhost/Twine/Tests/Test.html:26:26676)
at Object.k.fireWith [as resolveWith] (file://localhost/Twine/Tests/Test.html:26:27489)
at Function.o.extend.ready (file://localhost/Twine/Tests/Test.html:26:29283)
at HTMLDocument.I (file://localhost/Twine/Tests/Test.html:26:29453)
(For example, you might first navigate to Test.html, then add a new location to the URL, e.g. Test.html?nav=Later. If you then hit the browser back button, you will have confounded the application's expectations, generating the error/stacktrace shown above.)
The relevant code:
:: Configuration [script]
config.disableHistoryControls = true;
config.startPassage = "Start";
:: StoryInit
<<script>>
... code to read URL queries into the opts object...
if (opts.hasOwnProperty("nav")) {
SaveSystem.deleteAuto();
config.startPassage = opts["nav"];
}
<</script>>
I'm not sure whether what I'm encountering is a bug in SugarCube--I'm not sure that programmatically changing the config option is really supported. Any ideas on what I can do here? Could I search through the browser window's history and eliminate any reference to my Twine's base URL before the currently running instance--if so, is there a safe way to do that?
Thanks for any help/advice!
EDIT: I have a minimal example and can supply if needed.
Comments
2. I think I know what's probably going on. I'll take a look at it.