Since both Javascript and Sugarcube's <<remember>> variables are supposed to use the web storage, I figured I would be able to somehow retrieve a Twine variable $var (set using the macro <<remember $var = 2>>) using the javascript code...
localStorage.getItem('var')
or...
localStorage.getItem('$var')
...neither of which are working for me. Is there another method made available for such an exchange?
Ultimately, I wish to be able to feed a Twine story data from a database via PHP script and JavaScript and then retrieve player decisions in the reverse direction, storing them in a database. Though I have been successful with plain html documents in doing this, I have yet to figure out how to using a Twine story. As of yet, my only options for controlling story flow have been to generate conditional statements based off of variables set using the Sugarcube macros.
1. How can I exchange the JavaScript and Twine web storage variables?
2. Is it possible to have JavaScript contained in a <<script>> tag to provide control flow systems without directly modifying the html content of document elements? Or would I need to simply rely on the macro system?
Comments
macroslib.js
) useful.As to why your first attempt failed. SugarCube's storage for each story is prefixed (first by a slugified version of the story's title and secondly by subsystem) and compressed to save space. You're probably better off doing your initial DB load simply as a section of the Story JavaScript, or as a macro if you don't plan on doing all of your loading at startup, and DB storing as a macro.
Also, the following undocumented static
Wikifier
methods may help: (they operate on the currently active state)