Howdy, Stranger!

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

Restoring a history as 'stretchtext'

edited September 2016 in Help! with 1.x
Hi dear Twine fellows :)

I am having some hard time at the moment trying to implement a save/load mechanism for my Twine project.
I am using Twine 1.4 and Jonah.

My project (described in this post) simulates a mobile text conversation between the player and a girl named 'Cat'.
Jonah format does a great job here by keeping all previous passages/dialogs displayed on the page while the player progress through the game.

Saving the history is not really a problem here, since we can access to the History object from Twine.
But the reload part is more complex : I would need the entire dialog history to be re-displayed so that the player don't loose anything and can still go back to a previous passage to make another choice.

I've tried a quick and dirty hack where I saved the part of the DOM where passages are displayed and then re-inject it at startup. It kind of works, all previous passages are properly displayed but the event handlers are now detached, meaning that links won't work anymore.
I thought I could try to re-attach them using .on jQuery function but I would prefer having a cleaner solution since I'd probably still encounter other issues.

Then I had a try using the bookmark used by Twine in the save/encode+restore/decode functions. Here, when restoring I would display all passages from the decoded history instead of the last one only. Again, this almost works but it means the whole history is being re-played and this is an issue for some macros such as <<either>> which lead to some inconsistencies.

As a side note : so far I used localStorage to save whatever needed to be saved but it doesn't seem that persistent (there are some bugs) and mobile OS could decide to wipe it off in case of memory shortage.
So I will probably have to use some Cordova plugin to store those save data safely, on mobile at least.

Here is where I stand, did anyone already try to achieve this kind of stuff? Any thoughts/advices?



  • edited September 2016
    re: <<either>> and randomly determined items.

    You may want to implement a seedable pseudo-random number generator like the one referenced by the State.initPRNG method in SugarCube 2's State API, and use a custom macro based on that instead of <<either>>. That way the 'random' outcomes will be repeatable as the History re-plays during your load method.
  • Thanks for the suggestion regarding the <<either>> issue, that would do the trick indeed :)

    Generally speaking, what do you think of my approach in order to restore a stretchtext history?
    I don't see any other way than 'replaying' all the passages until the last one the player visited last time he played.
  • I have never really looked at the bookmark based save system's source code before today but after a quick look at the History.encodeHistory method and the History.decodeHistory method the bookmark itself seems the ID of the current passage combined with a snapshot (delta) of the state as of the current passage.

    So I think you have (at least) two choices:

    1. Modify the existing encodeHistory so that it includes the passage path (the list of passage names stored in history) the reader took in the bookmark delta, and change decodeHistory to re-play that path. This is similar to what you proposed.

    2. Enhance Jonah to use a non-bookmark storage based history system similar to that used by SugarCube, which persists each moment (passage name and initial state) of each passage visited.
  • Thanks for your valuable input greyelf, as always :)
    I think probably stick with 1.
Sign In or Register to comment.