Howdy, Stranger!

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

Sugarcube 1 if autosave

edited January 2017 in Help! with 1.x
Is there a way to only trigger code if an autosave is available in sugarcube?

I have a load autosave button on my start screen that I only want to do stuff if the autosave is there, like e.g. stop the start screen music.

I tried just putting this code in the autosave passage but I realised that the autosave would reset any variables to their states at load so that didn't work too well since I couldn't control it with a variable from the start screen.

EDIT: The second thing would be more useful as then I can activate code immediately after any autosave load. Is there a way to have a persistent variable across an autosave trigger?

EDIT: I just read about "if (SaveSystem.autosaveOK()) { /* Code to manipulate the autosave. */ }" though still need to work out how to use this.

Comments

  • edited January 2017
    Save.autosave.has()
    

    Is what you probably want.

    As in:
    <<link "Continue">>
        <<script>>
            if (Save.autosave.has()) {
                Save.autosave.load();
            } else {
    	    UI.alert("No autosave found.");
            }
        <</script>>
    <</link>>
    

    What else exactly to do you want to add in?
  • I thought your syntax for
    SaveSystem.autosaveOK()
    

    looked weird, and that's because that's sugarcube 1 syntax. If you're running sugarcube 1, you should upgrade if you can. If you can't (like your project is already done or something), I think
    SaveSystem.hasAuto()
    

    Is the sugarcube 1 equivalent.
  • The SaveSystem.autosaveOK() method is not what you want. It only tells you if the autosave slot is available and ready for use, not if the slot is actually filled. As noted by Chapel, the SugarCube v1 SaveSystem.hasAuto() method is what you need.

    Also. I'm assuming the code you're referring to is TwineScript, but I'll give examples of both.

    Using it in TwineScript:
    <<if SaveSystem.hasAuto()>>
    	/* Autosave exists! */
    <</if>>
    

    Using it in JavaScript:
    if (SaveSystem.hasAuto()) {
    	/* Autosave exists! */
    }
    
  • Cool, that helps heaps, thanks. :) I want to upgrade to SC2 but the game runs as is and it's a non-essential task before I get the game demo out. I'll upgrade eventually.
Sign In or Register to comment.