Howdy, Stranger!

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

Any way to pull data/variables from a previous story?

I want to create a very long and episodic story that (ideally) remembers what choices a reader made in previous episodes. Otherwise, what's the point of them making the choices, right? ;D I'm wondering if there's any way to output data/saved variables at the end of a game, and have it remain accessible for the next game to pick up. (If it were possible for the data to survive across different browsers/computers, that would be most magical, but I think that's asking far too much...)

I can think of some janky workarounds (assign a number to each final screen in Episode 1; ask the reader to manually input that number at the beginning of Episode 2; etc.) but I wanted to see if there was a proper way to do it first. I'm in the process of learning Javascript right now, so please hold my hand gently on technical answers to this question.

I'm on Twine 1.4.2 and I'm open to using either Sugarcane or Sugarcube formats. Thanks in advance!

Comments

  • SugarCube has built-in (Story History) save functionality which includes a Save to Disk feature which persists all the saves to a file, those saves can be later restored by using the Load from File option.

    note: The Story History within a save includes information about each passage the Reader visited while navigating through the story and the state of all the variables for each of those visited passages.

    Now you could include a final passage in your story where you display state information which you ask the Reader to cut-n-paste into a file. You then could include a passage in the next story into which you ask the Reader to paste the information for the file.

    Or you could try to be tricky!

    When a pre-saved Story History is loaded the story Author has the ability to influence what happens during that load via the config.saves.onLoad option, and it may be possibly to modify the contents of the History being loaded but doing so could lead to errors.
  • edited October 2015
    greyelf wrote: »
    Or you could try to be tricky!

    When a pre-saved Story History is loaded the story Author has the ability to influence what happens during that load via the config.saves.onLoad option, and it may be possibly to modify the contents of the History being loaded but doing so could lead to errors.

    Ahhh this is such great news! I've only used Sugarcane in depth before, so I hadn't investigated Sugarcube's save systems. I had assumed it was only within each game rather than being able to save externally. Hooray!

    All that makes good sense, but I have a question about the 'tricky' part of your post. To make sure I'm understanding: what you're saying is, when the reader's previous Story History is loaded into the game, I could use the config option to mess around with some of the variables being loaded? Change their age to 12 instead of 15, for example. If I'm understanding correctly, I can definitely see how that might tangle up future code.

    Thanks again for the good news!


    edit So I tried the save to disk/load from file using two dummy games named Part 1 and Part 2. Tried to load the save file from 1 into 2 and naturally it showed an error that the save file's "%identity%" didn't match up. Did I do something silly?
  • What you want to do is possible. I don't have time to address this now, but I'll try to reply as soon as I can.
  • litrouke wrote: »
    All that makes good sense, but I have a question about the 'tricky' part of your post. To make sure I'm understanding: what you're saying is, when the reader's previous Story History is loaded into the game,
    There are two different types of Load:
    a. The loading of the external file contain one or more saves into the story.
    b. The loading of one of the save slots within the Saves list.

    I believe the onLoad feature relates to B.

    litrouke wrote: »
    edit So I tried the save to disk/load from file using two dummy games named Part 1 and Part 2. Tried to load the save file from 1 into 2 and naturally it showed an error that the save file's "%identity%" didn't match up. Did I do something silly?
    No, the save file internally tracks the identity of story that created the file in the first place, so by default you can't directly use the save file from one story within another story and thus the tricky part of my previous comment.

    You will need to set things up to for the Save to File -> Load from File cycle to work, and I would suggest talking to the @TheMadExile about what exactly is required for that to happen. Again remember I did say it was tricky!
  • @greyelf -- Gotcha! Thanks for the clarification. The process did seem far too easy. ;D If this gets too tangled, I may end up having a final screen in each episode that the reader needs to manually save, as you initially suggested.

    But hopefully @TheMadExile can present some alternatives! Looking forward to hearing your advice and thanks in advance for your time.
  • You haven't specified which version of SugarCube you're using, so I'm writing this for SugarCube 2.x (because no one should be using 1.x for new projects).

    greyelf wrote: »
    There are two different types of Load:
    a. The loading of the external file contain one or more saves into the story.
    b. The loading of one of the save slots within the Saves list.

    I believe the onLoad feature relates to B.
    SugarCube's save system actually doesn't care where saves come from, saving or loading, for the most part. Yes, the bits at the very edges of saving to slots and saving to disk are different, for obvious reasons, but most of the process is exactly the same. In particular, the config.saves.onLoad and config.saves.onSave functions are executed for all save types (autosave, slots saves, disk saves).

    litrouke wrote: »
    I want to create a very long and episodic story that (ideally) remembers what choices a reader made in previous episodes. Otherwise, what's the point of them making the choices, right? ;D I'm wondering if there's any way to output data/saved variables at the end of a game, and have it remain accessible for the next game to pick up. (If it were possible for the data to survive across different browsers/computers, that would be most magical, but I think that's asking far too much...)
    My suggestion would have to have a final/to-be-continued screen with a special save link/button for this purpose, which would save to disk (ensuring the save could be moved around and/or loaded in other browsers). It would still use SugarCube's save system, so loading the to-be-continued save of part N to start part N+1 would be trivial.


    Anyway, I've attached a ZIP archive of two Twine 1 examples for SugarCube 2.x, one for saving and one for loading. If you have any questions about the examples, please ask.

    PS: I added a special import button to the loading screen of the loading example, but it's not necessary. The save exports generated by the to-be-continued export button may be loaded by the standard Load from Disk button in the Saves dialog. I just figured that it would be nice to have right there on the loading screen.
  • @TheMadExile -- after trying your examples, I swore in excitement, slammed my hands on the table, and scared the shit out of both my cats. They may not appreciate your work so much, but I appreciate the hell out of it!! This works perfectly and thank you for all the explanatory notes too.

    Man, forget Disneyland... The Twine forums are where dreams come true. ;D
  • So what happened to TheMadExile attached examples? I don't see them in his post anymore. That's no good for others that might be interested in this topic/question.
  • @tryguy -- hmm that's odd... here's the file for you.

    @TheMadExile -- did you pull them purposefully or the forums just swallow them? I'll reupload in this post, but let me know if you'd rather have them pulled.
  • The forums dropped the file (it's happened before). I think it happens to posts with attachments when you accept the post as an answer.
Sign In or Register to comment.