Better Saving and Loading Dialog for Sugarcube

I wonder if anyone here has ever done or thought about doing a better dialogue for the Sugacube save system. You know, with a separate save and load dialog and a button to overwrite instead of load on the save dialog, would be very useful.

With the save API and dialog API described here you can do that.

I’ve attached a sample file that you can import into Twine but here is the code step by step

Expand code

In your StoryMenu passage

<<link "Save">>
<<run Dialog.setup("Save"); Dialog.wiki(Story.get("Save Menu").processText()); Dialog.open();>><</link>>

<<link "Load">>
<<run Dialog.setup("Load"); Dialog.wiki(Story.get("Load Menu").processText()); Dialog.open();>><</link>>

<<link "Delete">>
<<run Dialog.setup("Delete"); Dialog.wiki(Story.get("Delete Menu").processText()); Dialog.open();>><</link>>

Then you need to make passages for each dialogue. In one titled Save Menu

<<if (Save.slots.has(0))>>
  <<link "Overwrite into Slot 0">>
    <<run Save.slots.save(0); Dialog.close();>>
  <</link>>
<<else>>
  <<link "Save into Slot 0">>
     <<run Save.slots.save(0); Dialog.close();>>
  <</link>>
<<endif>>

In a passage titled Load Menu

<<if (Save.slots.has(0))>>
  <<link "Load Slot 0">>
    <<run Save.slots.load(0); Dialog.close();>>
  <</link>>
<<else>>
  Slot 0 is empty
<<endif>>

and in a passage titled Delete Menu


<<if (Save.slots.has(0))>>
  <<link "Delete Slot 0">>
    <<run Save.slots.delete(0); Dialog.close();>>
  <</link>>
<<else>>
  Slot 0 is empty
<<endif>>

To hide the old saves menu, add #menu-item-saves {display: none}.

Other considerations:

In the save/load/delete passages, you will need to repeat the code block within the same passage for every save slot and increase the slot number in the code (0 in the above examples).

In a blank script passage, you can define the max number of save slots you want to allow, for example Config.saves.slots = 3; . Slots are zero-indexed so three slots in your code will use slot(0), slot(1), and slot(2).

In front of each save/load/delete link you might want to add, for example, a title. This is more complicated but you can use save objects as described here here.

Finally, use your preferred method of line control. I like to add the ‘nobr’ tag to passages, then add manual line breaks with <br> in the passage text.

Save Dialog Sample.html.zip (155.3 KB)

1 Like

Thanks! That will help me.

1 Like