EDIT: Checkpoints are out now!
I’m working on a new feature for ChoiceScript, and I’d like some feedback from y’all before I roll it out. The feature is called “checkpoints.”
To save a checkpoint, you’d use:
*save_checkpoint
Then, later, you’d give players the option to restore to a previous checkpoint, like this:
*choice
#Continue to the next chapter.
*finish
#Restore to the previous checkpoint.
*restore_checkpoint
When you *restore_checkpoint
, the player will “travel back through time” to the moment that *save_checkpoint
was called. This includes re-enabling any *disable_reuse
options that the player may have used after saving the checkpoint.
(Previously, if you wanted to implement checkpoints yourself, you’d have to use a *gosub_scene
to individually copy all of your stats to separate “backup” variables, and then use another subroutine to individually copy all of your stats from the backup to the main variables. This was tedious and error prone.)
Try it out
To try it, download the checkpoints
version of ChoiceScript.
https://github.com/dfabulich/choicescript/archive/refs/heads/checkpoints.zip
It’s not yet available in the ChoiceScript IDE or the official version of ChoiceScript, because I’d like to get feedback on it first.
Advanced checkpoint features
Checkpoints can be simple, but they can get much fancier.
- Check whether
*save_checkpoint
has happened yet - Run some code after restoring from a checkpoint
- Exclude some stats/temps from being restored
- Use multiple checkpoint “slots”
- Restore to the last checkpoint at any time from the stats screen
Check whether *save_checkpoint
has happened yet
If you *restore_checkpoint
before you *save_checkpoint
, your game will fail with an error:
startup line 48: Invalid
*restore_checkpoint
; we haven’t saved a checkpoint
(Is this the right thing to do? I think the only alternative would be to restart the game completely. Would that be better?)
You can use a magic variable called choice_saved_checkpoint
. It starts out false
, but when you *save_checkpoint
, it turns true
.
Run some code after restoring from a checkpoint
*save_checkpoint
will set a temp variable called choice_just_restored_checkpoint
and set it to false
.
*restore_checkpoint
will set choice_just_restored_checkpoint
to true
during the restoration process.
*save_checkpoint
*if choice_just_restored_checkpoint
You just restored!
Exclude some stats/temps from being restored
Some games track the number of times that you restore from a previous checkpoint, in order to deduct “points” for using the checkpoint, or to limit the number of times you can restore.
*restore_checkpoint
will look for a variable named checkpoint_exclusions
, like this:
*create checkpoint_exclusions "experience_points courage wisdom"
The excluded variables would not revert back to their old values when you *restore_checkpoint
.
*create checkpoint_uses 0
*create checkpoint_exclusions "checkpoint_uses"
*save_checkpoint
*if choice_just_restored_checkpoint
You just restored!
*set checkpoint_uses +1
You have restored from the checkpoint ${checkpoint_uses} times.
...
*choice
#Continue to the next chapter.
*finish
#Restore to the previous checkpoint.
*restore_checkpoint
Multiple checkpoint “slots”
When you use *save_checkpoint
or *restore_checkpoint
, you can specify the name of a checkpoint “slot.” This allows you to set multiple checkpoints, allowing players to go back just a little or a lot.
*save_checkpoint major
...
*save_checkpoint minor
...
*choice
#Go back a little
*restore_checkpoint minor
#Go way, way back
*restore_checkpoint major
(Each checkpoint slot gets its own variable. In this example, choice_saved_checkpoint_major
would be set to true
when you *save_checkpoint major
.)
Restore to the last checkpoint at any time from the stats screen
You can write code to restore from the stats screen like this:
[choicescript_stats.txt]
*stat_chart
...
*choice
#Done.
*finish
*if (choice_saved_checkpoint) #Restore from the last checkpoint.
*restore_checkpoint
Note that you’ll need *if (choice_saved_checkpoint)
to make sure the player doesn’t try to restore before the first checkpoint has been set.
What do you think?
Does this do what you need? Is there anything I forgot?
Do you think *restore_checkpoint
should fail with an error when you haven’t reached a checkpoint yet? Or should it just restart the game from scratch?
(I suppose that if it were to restart from scratch, you wouldn’t need *if (choice_saved_checkpoint)
in choicescript_stats.txt
. Maybe that’d be easier to use?)