Savepoint Sample Code

Note: I’m going to leave these templates up for reference, but I strongly recommend using the inbuilt ChoiceScript checkpoint code instead which has been implemented as of November 2023. It’s quicker, easier (especially for incorporating multiple slots), more flexible, and far less error-prone!

Hey all! I’ve made two template games for making save/load checkpoints for your game.

I’d noticed that there are a lot of instructions around on the forum about how to do this, but if like me you learn best by looking at examples, here you are!

Template 1: load to the start of the chapter or section that you just played.

Template 2: either load to the start of the chapter or section that you just played, or reload to the earlier chapter of your choice.

Both templates assume that you have a solid understanding of ChoiceScript.

In particular you will need to use *gosub_scene so if you are not confident using this command, do check out the wiki linked.

Hope it’s useful - let me know if you see anything wrong in it, or if you have any questions!

Also, do check out this quick way of generating your variable lists from uroboros-if on Tumblr.

44 Likes

Updated with a template for making checkpoints within a scene file, and a heads-up about using *create not *temp in those circumstances (thank you @Doriana-Gray!)

It was mentioned to me, and I saw comments elsewhere on the forum, that *hide_reuse and *disable_reuse behave incorrectly when using checkpoints in this way, and that when an option is picked on a previous playthrough, it’s not available to pick when replaying. However, when I tested the template I couldn’t replicate that and as far as I could tell, using those commands seems to be working…? Please let me know if you can shed any light, or if the template game behaves incorrectly for you, and I’ll amend as needed.

Edit: made another correction unrelated to the savepoint code - I was on implicit control flow autopilot and the error didn’t get caught by RT for some reason.

9 Likes

Great examples! That’s almost exactly how I did it in Parliament of Knives!

It gets tough when you have over a hundred variables, but it’s nothing a few hours of copy/pasting and a cup of coffee can’t overcome. :sweat_smile:

Edit: I don’t think I ever had a problem with chapter rewinding and *hide_reuse

6 Likes

Yeah, it’s how I’ve done it in Royal Affairs etc and it’s seemed solid. It’s a slog but I found it kind of satisfying in a weird way, haha! I’m doing it as I go for my new project which is its own slightly different faff :sweat_smile:

Good to hear that those commands have been working properly for you! I hadn’t heard anyone having trouble where I’d implemented it so I wonder if the code has changed since the posts I saw (from my cursory look, they were from a few years ago).

2 Likes

That’s one of my main issues with save points. I’ve literally had to remove every choice that has a “disable reuse” on it and set it as a choice variable that can be reset if I decide to add a save poin which is a heap more work and annoying to code. That’s interesting you’re not having problems with that though, has something changed more recently? (I’ve just assumed that it was continuing to be an issue.)

Yeah, I’m not sure if the code has changed in the meantime - please do poke around in the template and see if it behaves oddly, but I couldn’t get it to show the errors :sweat_smile: which is good news in principle, though a bit confusing.

By the way I’ve edited the first post to include a link to a guide to generate variable lists quickly!

2 Likes

Here I thought reuse resets on scene change. Maybe I misunderstood though, I haven’t exactly used it.

1 Like
*choice
	#Save and continue to next chapter.
		*finish
	#Reload to the start of Chapter 2.
		*gosub_scene savegame load
		*goto_scene chapter_2

LiliArch is correct, I think. If I change *goto_scene chapter_2 there with *goto [label] instead, to reload Chapter 2, the reuse commands will not reset.

1 Like

Can you check if that happens in the Chapter 3 section, where it uses *goto [label]? When I tested that section, the *hide_reuse and *disable_reuse seemed to work OK. I may well have missed something or have misunderstood, though, so please let me know if it isn’t!

They are working as intended…

I think when loading a save, we need to make sure we use *goto_scene [scene] or *goto_scene [scene] [label], which is what you do.

		*goto_scene chapter_2
		*goto_scene chapter_3 meet_dog
		*goto_scene chapter_3 meet_dog_again

These lines can be replaced with a *goto. But if they did and there are reuse commands, these commands won’t behave properly.

2 Likes

Ah, I get you! So *goto_scene must be used and not *goto, is that right? If I’m understanding right, I can add a note to the template as a heads-up.

1 Like

Yeah, on loading a savepoint.

That would be more human-friendly to me, easier to keep track of.

It would make sense to put the save/load code on a separate file anyway, yes?

Got it! I’ve added a note to the chapter_3 section about making sure to use *goto_scene.

Definitely, as it can be called from all different places and it makes it much easier to track everything. With this setup I just put all the checkpoint-related variable setting into a separate file.

1 Like

So glad I found this! Thanks for your work and the way you presented the system. I think I’ve got it running in a few of the hub zones of my WIP. Having a checkpoint style system like this will really encourage exploration!

Thanks so much!

1 Like

Amazing, I’m glad it’s helpful!

1 Like

hello, I just found this thread and want to asks you,

  1. does it mean that save system is technically just storing your datas in some variables that are declared in startup.txt but remains untouched as we play?

  2. if that’s the case, then does it mean all datas in all variables created are persistent even if we close the app on our phone?

sorry, I’m trying to understand how those datas work, technically, thank you

If it’s a released game, the saved variables will be kept whether or not a browser window or app is closed, the usual way players can keep their progress. So when playing a game like Royal Affairs which was released with checkpoints, you can stop playing in the middle of Chapter 3, for example, return to it later, complete Chapter 3, and then replay it using the checkpoint.

If it’s a WIP or otherwise unpublished game on Dashingdon or another website, refreshing or navigating away will lose progress including checkpoints. If CJW’s save plugin is enabled, that will keep your progress and if you loaded from a save slot, you could then also use the checkpoint to replay as desired.

Oh! I didn’t realise that. That’s really handy to know. So if you load a save point as a goto_scene will it restore all the *disable_reuse choices to their original state (so all can be selected again)? If that’s all that’s needed it would be far easier for my future projects to just run it through a blank scene or a reload save scene and then back again to the original file rather than fluffing around with choice variables that get reset with the saves.

I’ve added another template for reloading to the earlier chapters of your choice:

Let me know if it’s not working as intended or if anything’s unclear!

4 Likes