0 votes
by (440 points)
How do I make?

My story has a UI-Bar disable, but I want the story do Auto-save in determined passages (with all current variables).

When the game begins ask "new game or continue game", if click continues, this load the auto-saved game. And if click on a new game, I want show warning about overwrite.

1 Answer

0 votes
by (159k points)

SugarCube 2 has a built-in Auto Save/Load system that can be used in a number of different ways, in your particular use-case you could do the following.

1. Configure the Auto Save/Load system within your story's Story Javascript area.

You can use the Config.saves.autosave setting to tell the system to automatically save whenever the end-user views a Passage that has been assigned a known tag. (eg "autosave"), and use the Config.saves.autoload setting to tell the story format engine to prompt the end-user if an autosave exists when the story (re)starts up.

/* Do an autosave for all passages tagged with "autosave". */
Config.saves.autosave = "autosave";

/* Prompt the end-user to load the last autosave if there is one. */
Config.saves.autoload = "prompt";

2. Assign a known tagged (like autosave) to each of the Passages you want to do the autosave in.

By default a Moment is added to the story's History each time the end-user transitions from one Passage to another (can be same Passage), each Moment consists of the Name of the Passage about to be shown as well as a copy of the current value all known story variables as they were BEFORE the content of the Passage to be shown is processed. This means that any changes to story variable values made within the Passage being show will not be included in the moment.

A Save (including an Autosave) basically consists of a copy of the story History at the time the save was made, and the loading of a Save basically returns the story History back to what it was when the Save was made. The engine then processes the Passage named in the last moment of that History.