Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[SugarCube] Best way to test version

For my WIP (SugarCube v0.9.9), I need to be able to wipe the user's locally stored saves and options when I post a new version of the Twine HTML file. My thought is that I would store the version as a property in the options object and check on startup to see whether it has changed; if it has, wipe the existing data stores.

I'm wondering:

1) StoryInit seems like the best place to do this. Is there any reason to think otherwise?
2) Is there already a version number present somewhere in the HTML file that I could use for this purpose, or will I need to manually version it? The IFDB doesn't list IFIDs for Twine files, and there also doesn't seem to be a version of any sort in the Twine HTML file.
3) Are these indeed the best ways to wipe the save and option stores?
SaveSystem.purge();
<<deleteoptions>>
Thanks for any help!

Comments

  • Your bullet points:
    [list type=decimal]
    There's not much point in waiting for StoryInit to be run, that's pretty deep down the rabbit hole.  Ideally, I think that you'd want to do this as soon as you could.
    Twine/Twee do not version the compiled HTML, so you would need to do it manually.
    Those would work, yes.

    And, I can't say that I'd recommend storing your version in options.

    For the moment, I'd suggest something like this:

    :: Version &amp; Reset [script]
    setup.version = "whatever";

    // if the stored version does not exist or is inequal to the current version,
    // then delete the user's options and saves
    var storedVersion = storage.getItem("version");
    if (storedVersion === null || storedVersion !== setup.version) {
    // purge them all
    storage.removeItem("options");
    SaveSystem.purge();

    // store the new version
    storage.setItem("version", setup.version);
    }
  • Great, and thanks for the code! I assume that storage is an API for however browser storage is done (i.e., LocalStorage when available)?
  • Yes, storage is an instance of SugarCube's key/value storage API.  In particular, it's used for persistent storage (there's a separate instance for temporary per-session storage).  And yes, currently, persistent storage is handled by localStorage, if functional.  I plan to support indexedDB in the future as well, but I'm going to wait until it's a TR, at least.
  • Very nice, very simple. Thanks again for the great work on SugarCube!
Sign In or Register to comment.