# Savepoint Sample Code

**URL:** <https://forum.choiceofgames.com/t/savepoint-sample-code/137953>\
**Category:** ChoiceScript Help\
**Created:** [June 10, 2023, 9:35am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953 "2023-06-10T09:35:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [June 10, 2023, 9:35am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/1 "2023-06-10T09:35:46Z")

</div>

**Note: I’m going to leave these templates up for reference, but I strongly recommend using the [inbuilt ChoiceScript checkpoint code](https://forum.choiceofgames.com/t/new-in-choicescript-html-exports-checkpoints-and-achievements/144880) 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.

- [Playable version](https://dashingdon.com/play/hannahps/savepoint-example/mygame/)
- [View code](https://dashingdon.com/play/hannahps/savepoint-example/mygame/scenes/)

**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.

- [Playable version](https://dashingdon.com/play/hannahps/savepoint-example---multiple-load-points/mygame/)
- [View code](https://dashingdon.com/play/hannahps/savepoint-example---multiple-load-points/mygame/scenes/)

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

- [Intro to ChoiceScript](https://www.choiceofgames.com/make-your-own-games/choicescript-intro/)
- [Important ChoiceScript Commands and Techniques](https://www.choiceofgames.com/make-your-own-games/important-choicescript-commands-and-techniques/)
- [Advanced ChoiceScript](https://www.choiceofgames.com/make-your-own-games/choicescript-advanced/)

In particular you will need to use [\*gosub\_scene](https://choicescriptdev.fandom.com/wiki/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](https://www.tumblr.com/uroboros-if/719816324953653248/choicescript-savepoint-system-very-quickly) from uroboros-if on Tumblr.

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [June 10, 2023, 3:17pm UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/2 "2023-06-10T15:17:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GreekWinter](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/greekwinter/32/47097_2.png) [@GreekWinter](https://forum.choiceofgames.com/u/GreekWinter)\
**Post date:** [June 10, 2023, 4:29pm UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/3 "2023-06-10T16:29:47Z")

</div>

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. 😅

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

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [June 10, 2023, 4:41pm UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/4 "2023-06-10T16:41:04Z")

</div>

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 😅

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).

---

<div class="post-metadata">

**Author:** ![Jacic](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/jacic/32/7061_2.png) [@Jacic](https://forum.choiceofgames.com/u/Jacic)\
**Post date:** [June 12, 2023, 1:43am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/5 "2023-06-12T01:43:25Z")

</div>

> [@HannahPS](#):
>
> 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.

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.)

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [June 12, 2023, 8:02am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/6 "2023-06-12T08:02:36Z")

</div>

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 😅 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!

---

<div class="post-metadata">

**Author:** ![LiliArch](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/liliarch/32/120749_2.png) [@LiliArch](https://forum.choiceofgames.com/u/LiliArch)\
**Post date:** [June 12, 2023, 8:19am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/7 "2023-06-12T08:19:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Silver\_Eye](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/silver_eye/32/126178_2.png) [@Silver\_Eye](https://forum.choiceofgames.com/u/Silver_Eye)\
**Post date:** [June 12, 2023, 10:17am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/8 "2023-06-12T10:17:14Z")

</div>

```plaintext
*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.

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [June 12, 2023, 10:21am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/9 "2023-06-12T10:21:23Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Silver\_Eye](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/silver_eye/32/126178_2.png) [@Silver\_Eye](https://forum.choiceofgames.com/u/Silver_Eye)\
**Post date:** [June 12, 2023, 11:24am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/10 "2023-06-12T11:24:53Z")

</div>

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.

```plaintext
		*goto_scene chapter_2

```

```plaintext
		*goto_scene chapter_3 meet_dog

```

```plaintext
		*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.

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [June 12, 2023, 11:44am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/11 "2023-06-12T11:44:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Silver\_Eye](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/silver_eye/32/126178_2.png) [@Silver\_Eye](https://forum.choiceofgames.com/u/Silver_Eye)\
**Post date:** [June 12, 2023, 11:49am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/12 "2023-06-12T11:49:33Z")

</div>

Yeah, on loading a savepoint.

> [@LiliArch](#):
>
> It _would_ make sense to put the save/load code on a separate file anyway, yes?

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

---

<div class="post-metadata">

**Author:** ![LiliArch](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/liliarch/32/120749_2.png) [@LiliArch](https://forum.choiceofgames.com/u/LiliArch)\
**Post date:** [June 12, 2023, 11:50am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/13 "2023-06-12T11:50:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [June 12, 2023, 12:04pm UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/14 "2023-06-12T12:04:49Z")

</div>

Got it! I’ve added a note to the chapter\_3 section about making sure to use `*goto_scene`.

> [@LiliArch](#):
>
> It _would_ make sense to put the save/load code on a separate file anyway, yes?

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.

---

<div class="post-metadata">

**Author:** ![NumberedEntity](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/numberedentity/32/210906_2.png) [@NumberedEntity](https://forum.choiceofgames.com/u/NumberedEntity)\
**Post date:** [June 17, 2023, 10:40am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/15 "2023-06-17T10:40:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [June 17, 2023, 10:40am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/16 "2023-06-17T10:40:26Z")

</div>

Amazing, I’m glad it’s helpful!

---

<div class="post-metadata">

**Author:** ![Valda\_Reehux](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/valda_reehux/32/126891_2.png) [@Valda\_Reehux](https://forum.choiceofgames.com/u/Valda_Reehux)\
**Post date:** [July 5, 2023, 4:10am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/17 "2023-07-05T04:10:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [August 25, 2023, 9:13am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/18 "2023-08-25T09:13:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jacic](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/jacic/32/7061_2.png) [@Jacic](https://forum.choiceofgames.com/u/Jacic)\
**Post date:** [August 25, 2023, 10:04am UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/19 "2023-08-25T10:04:56Z")

</div>

> [@Silver\_Eye](#):
>
> These lines can be replaced with a `*goto`. But if they did and there are reuse commands, these commands won’t behave properly.

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.

---

<div class="post-metadata">

**Author:** ![HarrisPS](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/harrisps/32/240120_2.png) [@HarrisPS](https://forum.choiceofgames.com/u/HarrisPS)\
**Post date:** [August 25, 2023, 3:13pm UTC](https://forum.choiceofgames.com/t/savepoint-sample-code/137953/20 "2023-08-25T15:13:54Z")

</div>

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

- [Playable version](https://dashingdon.com/play/hannahps/savepoint-example---multiple-load-points/mygame/)
- [View code](https://dashingdon.com/play/hannahps/savepoint-example---multiple-load-points/mygame/scenes/)

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

[Next page](https://forum.choiceofgames.com/t/savepoint-sample-code/137953.md?page=2)
