Recently, I started to create an alternative saves / loads menu, and then I started the structure for that.
:: UserOptions
<div id="SaveMenu">
<div id="SaveMenuSlot-0" onclick="window.getSave(0)">
<div id="saveFont">1: <<if Save.slots.has(0)>>Has save valid! <<else>>Empty save<</if>></div>
</div>
...
</div>
10 slots, then at the click…
window.getSave = function(slot) {
if (SugarCube.Save.slots.has(slot)) {
setup.currentSave = SugarCube.Save.slots.get(slot)
setup.slot = slot;
}
else {
setup.currentSave = false;
setup.slot = false;
}
// Verify if the save is okay
if (SugarCube.Save.slots.ok()) {
console.log(SugarCube.Save.slots.get(slot))
}
updateSaveMenu()
}
And then the updateSaveMenu, returning the links with the functions and parameters to be executed.
const updateSaveMenu = () => {
window.refreshLinks()
setup.menuButtons.button1 = setup.mapButton("Save", false, { func: SugarCube.Save.slots.save, value: setup.slot })
if (setup.currentSave) {
setup.menuButtons.button2 = setup.mapButton("Load", false, { func: SugarCube.Save.slots.load, value: setup.slot })
setup.menuButtons.button3 = setup.mapButton("Delete", false, { func: SugarCube.Save.slots.delete, value: setup.slot })
}
else {
setup.menuButtons.button2 = setup.mapButton("Load", false, false)
setup.menuButtons.button3 = setup.mapButton("Delete", false, false)
}
setup.menuButtons.button15 = setup.mapButton("Return", setup.passageSave, false)
window.updateActionMenu()
}
This works structurally, but when the commands are executed, but in practice saves and delete do not happen, and loads through this method trigger an error.
One note, if I run this through a different medium, like <<button “Save!”>><<run Save.slots.save (1)>> <>, it works. So, I would like to ask what is going on, and how to resolve this bug.
Note: Here, the buttons structure.
setup.mapButton = function(buttonName: string, localToGo: any, callBack: any) {
const newLink: Button = {
name : buttonName
}
if (localToGo) {
// For battle system purposes, no keyboard changes needed
if (typeof localToGo === 'function') {
newLink.move = localToGo
}
else {
newLink.move = () => {
Engine.play(localToGo)
}
}
}
if (callBack) {
// Object function (func) and value (value) properties
newLink.callBack = callBack;
}
return newLink;
}