Creating a save system, starting by tackling var

I’m having trouble with building a save system. I have two areas of confusion, one is around coding and the other is more general.

Here is the general question - if a save system is created using choicescript and the game is published, my understanding is that the game sits inside an app. Also, that the app does not have a save system inbuilt? So, if a player saves the game - where does it go? Into cache?

secondly, To build a save system I believe I have to do the following:

Create a scene , I will call it gamesave

In the scene, I create a variable save for every variable , so here is an excerpt from the startup:

*create max_stamina 0
*create max_luck 0
*create max_skill 0
*create stat1 100
*create bullets false
*create bullets_number 0
*create bulletclip false
*create diceresult 0
*create dicetoroll 0
*create dicesides 12
*create dicesix 6
*create male false
*create female false
*create gm false
*create gf false
*create sm false
*create sf false

and in gamesave I do this:

*create max_stamina_save 0
*create max_luck_save 0
*create max_skill_save 0
*create stat1 100_save 0


Am I correct so far? Some of these variables are not relevant to a save state or not, for example dicesides and the stats of characters you fight along the way

How can I save the variable of true or false please?

This is what I have so far, just using Luck to keep things simple for testing
This is sample code provided as an answer before:

*label save
*set alt_var1 var1
*set alt_var2 var2
*set alt_var3 var3

*label load
*set var1 alt_var1
*set var2 alt_var2
*set var3 alt_var3

This is my code:
*label save
*create max_luck_save 0

*label load
*set max_luck_save

I think I have it wrong? This will set luck to zero?

1 Like

I’m not very knowledgeable about coding yet, but I found another post by @Mert about the save system. I’m not sure if it’s quite what you’re looking for, but @eposic goes into great detail about the password system there.
The title is “About “Save” System”.

It does, but not the kind you’d think. It saves current progress only.

Into memory. The second set of variables does the saving.

Here’s a simplified example with only 3 vars total. In startup.txt, make an additional copy of all your *create variables and name them accordingly:

*comment standard vars
*create name ""
*create int 0
*create dex 0

*comment save vars
*create name_save ""
*create int_save 0
*create dex_save 0

Then in a gamesave.txt do the following:

*label save
*set name_save name
*set int_save int
*set dex_save dex

*label load
*set name name_save
*set int int_save
*set dex dex_save

Tune it to however many variables you have in total.

Then right at the beginning of a chapter 2 (for example) do this:

*gosub_scene gamesave save

That will save the game. At the end of chapter 2, if player wishes to restart it do this:

Onto the next chapter or start over?
		*gosub_scene gamesave load
		*goto_scene chapter2
	#Onto chapter 3
		*goto_scene chapter3

Same with death sequences. Except you don’t go to the next chapter, but to an ending scene.

Thank you massively, this save system is all that is standing between me and finishing the game so thanks!

I also appreciate this question does seem to come up , having read through the previous forum Q&A I have ended up even more confused.

Can I please double check this aspect? I will use examples from my actual startup:
Here are two variables. The max stamina is a result of the player choosing allocation of points and is a numeric value and the male false is a boolean value of true/false

I Think I have copied the example of a numeric value correctly from above, although I can’t visualise in my head what is happening

I don’t know how to deal with a true or false?

*comment my current variables
*create max_stamina 0
*create male false

*comment save vars
*create max_stamina_save 0
*create male ???

Then in a scene folder
*label save
*set max_stamina max_stamina
*set male ???

*label load
*set max_stamina_save max_stamina

*comment my current variables
*create max_stamina 0
*create male false

*comment save vars
*create max_stamina_save 0
*create male_save false

Then in a scene folder
*label save
*set max_stamina_save max_stamina
*set male_save male

*label load
*set max_stamina max_stamina_save
*set male male_save

A bit OOT, do you use [male=true] (and female=true) for gender? Why not [gender=male] or [gender=female]? Or go numeric and [gender=1] [gender=2] (and 3+ for additional genders)?


Hi Szaal,
Thanks indeed, you and Jumo and many others have been exceptionally patient with all my posts, which I imagine come across a little bit like when a toddler keeps asking why the sky is blue…!

I used male= true and female= true because I wrote the whole thing originally as playable male only. I did this three years ago and based everything on my memories of the original fighting fantasy gamebooks. It never occurred to me then that there was anything like choicescript etc.

Having finished the game I now see it is vital to offer a choice.

I attempted to use 1, 2 3, and the ${} function but I couldn’t get the hang of it and instead went through the whole thing using if (male = true) etc etc. I did it yesterday in one mammoth session

I can’t believe the game actually works and because it does I am terrified to make any changes. It is a bit like a massive tower of cards and adding just one more will make it all tumble down!

I have been really blown away by how supportive everyone on this forum has been and don’t want to end on a sour note but I can see that I do not have the skills/brainpower/intelligence etc for the coding aspect. It is no exaggeration to say that I simply could not have gotten anywhere at all without your help and that of everyone else in the technical forum.


Technically, if you have a boolean male variable you don’t need a female one.

If this is what you have:
male = true
It means the character is male.

But if what you have is this:
male = false
Then the character is female.

However if you have both a male and female variable you can have a nonbinary character as well if both of the variables are false (or both are true).

1 Like

Many thanks, good info

No problem, glad to help :slight_smile: Let me try to explain the basics: you have 2 sets of variables that mirror each other. One set is called slightly differently, because in CS a variable can only hold 1 value.

Now, when you start a chapter you take all your var values from standard set and copy them to your second “save” set of vars:

*label save
*set stamina_save stamina

Notice the order of variables. You take “stamina_save” and assign it value from “stamina”. It doesn’t matter what type of data the var holds, as long as two are the same. No need for true/false, “” or 0/1. Just variable names.

Now you have 2 sets of vars with identical values at chapter start.

As the chapter progresses, standard set has its values change. Then when chapter ends how do you replicate a past state of the game? You do the reverse. Take your backup set of vars and copy its values to your standard set.

*label load
*set stamina stamina_save

Again, order of variables. You take “stamina” and assign it value from “stamina_save”.

Now your standard set has values exactly like they were during chapter start. All that is left is *goto_scene to the top of the scene file.

Hope that clear up the workings of that code snippet.


Really brilliant, thanks!

1 Like

Was there a reply that solved the save system problem? If so, make sure to mark it with the Solution button so that others with the same problem can find their solution easier. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.