Howdy, Stranger!

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

Autoloading an autosave with Twine 2/Sugarcube 2

Hey all. Basically what I'm trying to do is load up a title screen in my game, click "Begin" to begin the game, then go to a passage which loads the game's autosave, and if there is no autosave, goes to the first passage of the game. I have found the Save API, but don't really know how to do anything with it (I didn't even know how to create my own macro before this, to illustrate my complete lack of knowledge with JavaScript, though my programmer background has helped me pick up on the basics). I can't seem to load anything or do anything. I assume the game automatically saves to the auto-save slot whenever the player does something - if I'm wrong about this, clarification would be appreciated. If anybody could show me how best to simply do the above, I would really appreciate it. Thanks so much!

Comments

  • At the top of the Save API documentation is a note explaining that there are Configuration options for controlling how save and auto-save work, the note even contains a link to the section containing the autoload / autosave related options.
    The configuration options are generally placed within your story's Story Javascript area.

    If you look at the examples for the autoload / autosave related options you will see that you can configure SugarCube to prompt the Reader if there is an autosave to load.
    Config.saves.autoload = "prompt";
    Config.saves.autosave = true;
    

    Commonly there are passage within your story where you do not want autosave to occur like at the very start of your story, as explained in the documentation you can use the Config.saves.isAllowed option to control when autosave is allowed

    You could use code like the following which will not do an autosave for any passage that has been assigned a nosave passage tag.
    Config.saves.isAllowed = function () {
        return ! tags().contains("nosave");
    };
    
  • edited August 2016
    To avoid annoying popups, I prefer to inlude it in a link like so:
    <<click "Load Autosave">><<script>>SaveSystem.loadAuto()<</script>><</click>>
    

    The other advantage to this is if you want to have any other commands activate on clicking that link (like setting variables) you can insert them before the <<script>> macro. For example, in my story I use that to stop the title screen music upon clicking load autosave. If you let the game do it automatically anything running on the title screen will just keep going until it gets stopped, as the simple act of loading an autosave does not halt anything currently in progress.

    Eg.
    <<click "Load Autosave">><<playlist stop>><<script>>SaveSystem.loadAuto()<</script>><</click>>
    


    I recommend against always making the player load an autosave, as for whatever reason they might want to restart from the beginning again. However, you could do it easily with variables like so:

    1. on the screens where you have a tagged autosave activating, write

    <<set $autosave to true>>

    2. On your start game screen write:
    <<if $autosave is true>><<click "Begin">><<script>>SaveSystem.loadAuto()<</script>><</click>><<else>><<click "Begin" "First Passage">><</click>><</if>>
    

    Where "First Passage" is the very next passage after the start screen.

    I prefer to control these things with variables and click events for maximum customization.


    In my game I prefer to limit where a player gets autosaved to avoid any confusing bugs arising so use
    config.saves.autosave = "autosave";
    

    in the script passage to autosave only on passages I tag autosave. I then put these at key save points (the start of every turn), so a player is always loaded in at the same relative spot, rather than all over the place.
Sign In or Register to comment.