Looking to change buttons on the save menu

So, I’m looking to do a few things:

First, I’m looking to disable the player’s ability to save in slot 0. I’m using that slot for autosaves, and I’d like to keep it that way.

Second, I’m looking for a way to enable overwriting for the other slots, rather than having to delete the save in order to make a new one.

I did find a section on here telling me how to do that, by building a new save dialogue box, and I used that with other help to make buttons that did what I wanted, but the issue was, it did not label the saves. Sure, a little bit of text could label them as "Slot 1: " and "Slot 2: ", but I can’t seem to find a way to display a save’s title as text.

So, either I need to find a way to make the save screen display the buttons I want, which seems like it might be harder, or I need to find a way to display the save title as a string of text, which sounds like it should be easy. Either one will work, or both.

I started my first project not too long ago, so I’m relatively new to programming in general. I’m trying to learn as I go, and it has led to several revisions when I realised I could do something easier. I have less than two months of experience.

1 Like

Hi!
Some questions first:

  • Which version of SugarCube are you currently using? Because 2.36 and 2.37 have different save structures.
  • Are you using the built-in Save popup (there are AutoSaves included, you need to use the correct API to enable it in JavaScript) or did you create a custom one (if this case, please share your code)?
    • This applies to your second question too, because the built-in Save popup doesn’t have an overwriting. If you save, the save button becomes a load-the-save button.
1 Like

I am using SugarCube 2.37.0.

I had originally wanted to use the built-in save popup, and one of the answers I was seeking was whether or not I could put in a button to overwrite. This would remove the need to delete the save just so you could save it again.

If doing so is not possible, then the code I cobbled together is as follows:

In StoryMenu:

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

And in another passage marked “Save Menu”:

Autosave: \
<<if (Save.slots.has(0))>>\
<<button "Load">>
<<run Save.slots.load(0); Dialog.close();>>
<</button>>\
(this is the text I'm trying to set)\
<<endif>>\
<<if (Save.slots.has(0))>>\
<<button "Delete">>
<<run Save.slots.delete(0); Dialog.close();>>
<</button>>\
<<endif>>
----
Slot 1: \
<<if (Save.slots.has(1))>>\
<<button "Overwrite">>
<<run Save.slots.save(1, $PlayerName + ", Day " + $Date + ", " + $Location); Dialog.close();>>
<</button>>\
<<else>>\
<<button "Save">>
<<run Save.slots.save(1, $PlayerName + ", Day " + $Date + ", " + $Location); Dialog.close();>>
<</button>>\
<<endif>>\
<<if (Save.slots.has(1))>>\
<<button "Load">>
<<run Save.slots.load(1); Dialog.close();>>
<</button>>
(This is the text I'm trying to set)\
<<endif>>\
<<if (Save.slots.has(1))>>\
<<button "Delete">>
<<run Save.slots.delete(1); Dialog.close();>>
<</button>>\
<<endif>>
----
(Et cetera for four other save slots, total 5 + autosave)

The script that saves to slot 0 (the autosave) is at the top of the “Advance Time” passage, so that it saves every time you go from morning to afternoon, afternoon to night, and night to following morning. That code is:

<<run Save.slots.save(0, $PlayerName + ", Day " + $Date + ", " + $Location); Dialog.close();>>

I based my code on a bit of code from here on the forum (I would link to it to give credit, but I just received an error message saying I’m not allowed to post links yet). They mentioned using a title and linked to a section of the documentation, but I found myself unable to follow beyond that point, lacking the experience.

That’s why I want to know if I can recall the save’s title and display it on the Save Menu, and if so, how to do that.

I hope that helps you help me.

Ah well, yeah. Like I said in the original message, the Save codes in SugarCube drastically changed when moving to 2.37. The Save.slots APIs have been deprecated and changed completely (see documentation) along with many other changes.

So you would need to update your code.

BTW, <<endif>> is from an very old SugarCube version, you should use <</if>> instead (documentation).

The following should work (untested):
For your pop-up:

<<link "Save">>
   <<run Dialog.create("Save").wikiPassage"Save Menu").open();>>
<</link>>

For your regular saves (though it’s applicable to the Autosave too) - (also untested as a whole, but it should work):

<<if (Save.browser.slot.has(1))>>\
   <<button "Overwrite">>
       <<run Save.browser.slot.save(1, $PlayerName + ", Day " + $Date + ", " + $Location); Dialog.close();>>
   <</button>>\
<<else>>\
   <<button "Save">>
      <<run Save.browser.slot.save(1, $PlayerName + ", Day " + $Date + ", " + $Location); Dialog.close();>>
   <</button>>\
<</if>>\
<<if (Save.browser.slot.has(1))>>\
   <<button "Load">>
      <<run Save.browser.slot.load(1); Engine.show(); Dialog.close();>>
   <</button>>
 <<print Save.browser.slot.get(0).desc>> <- name of the save
<</if>>\
<<if (Save.browser.slot..has(1))>>\
   <<button "Delete">>
      <<run Save.browser.slot..delete(1); Dialog.close();>>
   <</button>>\
<</if>>
1 Like

Well, that almost worked.

I put it into my code and tried to run it, and after noting what errors it threw, I was able to make it work as intended.

Here’s the Popup:

<<link "Save">>
   <<run Dialog.create("Save").wikiPassage("Save Menu").open();>>
<</link>>

And here’s the Autosave and first slot:

Autosave: <<if (Save.browser.slot.has(0))>>\
   <<button "Load">>
      <<run Save.browser.slot.load(0); Engine.show(); Dialog.close();>>
   <</button>>\
 <<print Save.browser.slot.get(0).desc>>/* <- name of the save */\
<</if>>\
<<if (Save.browser.slot.has(0))>>\
   <<button "Delete">>
      <<run Save.browser.slot.delete(0); Dialog.close();>>
   <</button>>\
<</if>>
----
Slot 1: <<if (Save.browser.slot.has(1))>>\
   <<button "Overwrite">>
       <<run Save.browser.slot.save(1, $PlayerName + ", Day " + $Date + ", " + $Location); Dialog.close();>>
   <</button>>\
<<else>>\
   <<button "Save">>
      <<run Save.browser.slot.save(1, $PlayerName + ", Day " + $Date + ", " + $Location); Dialog.close();>>
   <</button>>\
<</if>>\
<<if (Save.browser.slot.has(1))>>\
   <<button "Load">>
      <<run Save.browser.slot.load(1); Engine.show(); Dialog.close();>>
   <</button>>\
 <<print Save.browser.slot.get(1).desc>>/* <- name of the save */\
<</if>>\
<<if (Save.browser.slot.has(1))>>\
   <<button "Delete">>
      <<run Save.browser.slot.delete(1); Dialog.close();>>
   <</button>>\
<</if>>

It was pretty close as you wrote it, and I would say that this solves my problem.

And just as a side note, the only reason I used <<endif>> instead of <</if>> is because I copied and pasted from the other code. All of my conditional statements have ended with <</if>> when I wrote them out myself.

Thank you very much for your help.