Because my current story is long, I added an auto-save system to it. That way, if you stop playing part-way through and then come back to it, it'll let you continue where you left off. In case others might find it useful, I'm posting it here.
These instructions work as of Harlowe 1.2.1.
1. Set Variables in a Startup Passage
In a
startup passage, put the following code:
{
<!-- Set autosave variables -->
(set: $_version to "VERSION NUMBER")
(set: $_autosave_slot to "autosave")
(set: $_autosave_filename to "save v"+$_version)
(set: $_start_passage to "THE REAL START OF THE GAME")
}
Change "VERSION NUMBER" to something like "1.0". Every time you re-release your story, change the version number so the story doesn't try to restore an autosave from a different version.
Change "THE REAL START OF THE GAME" to the name of the passage where your game actually starts. We'll need this because, here in a second, we're going to add a new startup passage that will let the player reload an autosave.
2. Save the Game in a Header Passage
In a
header passage, put the following code:
{
<!-- Auto-save our progress (unless a passage forbids it) -->
(unless: (passage:)'s tags contains "nosave")[
(save-game: $_autosave_slot, $_autosave_filename)
]
}
Now, every time a new passage loads, the game is saved. If you don't want the game saved on a certain passage, add the "nosave" tag to it.
3. Offer to Reload the Autosave in a New Passage
Finally, create a new passage and set it to be your starting passage. In it, put the following:
{
<!-- Set initial variables that change here instead of in the Startup passage -->
<!-- YOUR VARIABLES GO HERE -->
(unless: (saved-games:) contains $_autosave_slot and (datavalues: (saved-games:)) contains $_autosave_filename)[(goto: $_start_passage)]
}''[[NEW GAME->$_start_passage]]
(link: "CONTINUE")[(load-game: $_autosave_slot)] (link: "No")[(goto: $_start_passage)]''
If you've got any variables that you initialize in a startup passage and then change during the story, move 'em into this new passage. Otherwise they'll always be reset after you load your game.
Restarting the Story or Loading a Different Saved Game
If you ever want to re-start the story in the middle of it, you'll have to get rid of the autosave. Harlowe currently doesn't have a way to delete a saved game, but you can cheat by giving the autosave a new filename.
(save-game: $_autosave_slot, "not-a-real-save")
(reload:)
If you add other save slots, you'll need to include the "(save-game: $_autosave_slot, "not-a-real-save")" bit before you restore the game, too.
Comments
When it comes across advance link types (like the NEW GAME->$_start_passage link in the example) it will generally do one of three things:
1. Ignore the link and not create a missing passage.
In this case you will need to create the missing passage yourself.
2. Create an incorrectly named passage.
In this case you will need to rename the passage yourself.
3. Create a passage that is not needed. (your situation)
In this case you will need to delete the passage.
In your test game, make the following change:
The second thing is that the passage where you offer to reload the game needs a "nosave" tag. I completely left that step out of my original instructions.
So 1. change the value of $_start_passage, and 2. in your "start" room, add the "nosave" tag and see if it works.
I may try eventually to hack your script to save only at certain passages when a link is clicked IE: sleeping in a bed to set a save point.