Is there a way to create checkpoints?
Mr.Dot
28 Apr 2021, 17:09Like, instead of when you hit the restart button you go to a certain point and not the very start?
- How do you remove the "Restart" link at the top
- Is there a way to create a checkpoint or do you just do
[[Restart]](checkpoint1)
K.V.
28 Apr 2021, 18:42Hello.
Squiffy games automatically save the progress in the browser's local storage.
The only way to start a game from the beginning is by clicking that restart button (unless the user clears their browser's local storage).
So, hiding that restart link is not advised, but you can do it by hiding the HTML element via JS (or jQuery).
https://www.w3schools.com/jquery/eff_hide.asp
You should be able to use the browser's local storage to store checkpoints.
https://www.w3schools.com/html/html5_webstorage.asp
Bluevoss
29 Apr 2021, 15:05There are issues with this, right? What do you lose if you save? I've not had a lot of luck restarting a game. Well, one of my games.
K.V.
29 Apr 2021, 15:31I've not had a lot of luck restarting a game. Well, one of my games.
Is it public? I could test it on my system for you, just to see if it doesn't like me either.
Also, to avoid working on what I'm supposed to be working on, I'm about to make a quick game to test checkpoints. :)
K.V.
29 Apr 2021, 18:35I tried to find a way to do this by only using the game's code -- without editing any CSS or HTML files.
This seems to work, but it seems like it could be done better:
BAD CODE REMOVED
Clicking RESTART should ask if you want to start from the beginning or from the checkpoint:
EDIT
Ah! I was writing a reply at the same time as mrangel, and his post made me realize that my code was no good. All my code really did was use squiffy.story.go()
to go to whatever section name was saved in the local storage under "checkpoint". That did not really create checkpoints.
mrangel
29 Apr 2021, 18:38You could implement a kind of checkpoint by looping over all attributes in localstorage and serialising them into a single attribute; if the player wants to go back to the checkpoint, you just unpack them all.
If you want to disable 'saving' between checkpoints (which is a bit weird, because attributes are always in LocalStorage, which the browser saves between sessions), you could set the _transition
script to return to the previous checkpoint; this runs as soon as the player opens a game which has existing data in LocalStorage. You would presumably want to replace the squiffy.story.save
function with one which doesn't save the output (you'd do that manually at checkpoints), but which resets the value of _transition
to prevent squiffy.story.go
clearing it.
I don't think this would be too hard to achieve.
mrangel
29 Apr 2021, 18:40Ah, we answered at the same time :)
KV has a simpler kind of checkpoints, which would allow you to return to a specified checkpoint, but would keep any flags or attributes set after that point.
K.V.
29 Apr 2021, 18:49KV has a simpler kind of checkpoints
Oh, yeah... It was no bueno.
It wouldn't even have cleared anything saved between creating the checkpoint and restarting from the checkpoint.
As soon as I read your post, I was like, "oh, damn it! I forgot to cover 3/4 of the bases!"