Simple Save and Load Buttons (SugarCube 2.34.1)

Hello guys!
I’m new to Twine (less than a week of usage), and would like to ask how to achieve some basic “Save” and “Load” buttons with simple functions. Please see the picture I made below:

My Twine version is 2.3.15 with SugarCube 2.34.1 as the Story Format. I don’t want to use the default sidebar with saving and loading capabilities. I don’t even need the multiple slots. The “Save” buttons only appear on every chapter title or cover (acting like a chapter bookmark). So whenever the reader opens the story file (html) again, they will always return to the chapter they last clicked the “Save” button once they click the “Load Chapter” button on the Main Menu.

It is somewhat similar with the following codes for the Harlowe ones:

For Saving:

(link: "save")[(save-game: "file A")]

For Loading:

(link: "load")[(load-game: "file A")]

Also, if possible, I want the “Load Chapter” button to be disabled by default since nothing is saved yet, or at least alter the error message (if there are any) to something like “Can’t load a chapter.”

Thanks guys :slight_smile:

1 Like

For the save button

<<link "Save">>
   <<run Save.slots.save(0)>>
<</link>>

For the load button

<<if Save.slots.has(0)>>
  <<link "Load">>
     <<run Save.slots.load(0)>>
 <</link>>
  <<else>>Nothing to load
<<endif>>

You should probably set save slots to one by creating a new script passage and entering this

Config.saves.slots = 1;

More documentation is here. If you are only using one slot, you may want to consider the autosave feature.

Edited: fixed an error, thank you @TheMadExile

1 Like

Your <<else>> is in the wrong position and you shouldn’t use the deprecated <<end…>> style. Try:

<<if Save.slots.has(0)>>
  <<link "Load Chapter">>
    <<run Save.slots.load(0)>>
  <</link>>
<<else>>
  Nothing to load
<</if>>
2 Likes

Thanks a lot, guys! :blush: