Saving progress through restarts in ChoiceScript



I have been dreaming up an idea for a game to write. I finally got one, but I realized that the reader is going to have an unsatisfactory ending a lot of the time and as such will quickly get bored of replaying the same continent as they search for the true resolution of the game. My solution to this was to have changes in the story based on the choices that you made in previous runs. Not particularly major changes, but mainly breaks in the fourth wall and other small innuendos directed toward the player regarding their earlier runs. To do this, I need to be able to save information from prior games. From what I know of ChoiceScript this seems rather hard. My ideal solution (preferably without using java script) would be to write to a file which I could later read back variables from, but any way to store an unspecified amount of information between playthroughs would work. Is there any way that I can do this in ChoiceScript? Without it I doubt that I could make my idea palatable to play.

Also, is there a way to generate a random number? I’ve looked at the help and I haven’t seen it. This isn’t a necessary thing, but I would like to use it to be able to further vary the game between playthroughs.

Thank you for your help


Storing info can be done using *input_number or *input_text. Check out Guenevere’s save mechanic.

*input_text var_text
*input_number var_num 1 10

The above allows the player to input a number between 1 and 10 inclusive. Where you seek to randomise variable ‘var_num’ between 1 and 10, inclusive, use *rand :slight_smile:

*rand var_num 1 10

In both cases you can use *if to interpret the input:

*if var_num = 1
  Varied story text 1
*if var_num = 2
  Varied story text 2

Getting more complicated, you can store the data in a series of booleans. This is the equivalent of a ‘seed’, possibly comparable with the way that other games generate different maps in different playthroughs.

*rand var_num 1 3
*if var_num = 1
  *set story_path_1 true
*if var_num = 2
  *set story_path_2 true
*if var_num = 3
  *set story_path_3 true

*if story_path_1 = 1
  Varied story text 1
*if story_path_2 = 2
  Varied story text 2
*if story_path_3 = 3
  Varied story text 3

Or if you are a programmer, you can use choicescript to work out the length of a variable, or interpret a specific part of a variable. I don’t recommend this unless you are really well acquainted with CS (arguably it also doesn’t add much value).

*set choice_seed 12
Page 1 
*if choice_seed#1 = 1
    #Go to the market.
    #Go to the castle.
*if choice_seed#1 = 2
    #Go to the tournament.
    #Go to the prison.

Page 2 
*if choice_seed#2 = 1
    #Talk to the squire.
    #Talk to the arms master.
*if choice_seed#2 = 2
    #Talk to the stable girl.
    #Talk to the priest.

Well done, you finished the story! If you play again, inputting:


will give you a different story experience on your second read through.

Page 1 checks the first number of choice_seed. Page 2 checks the second number of choice_seed. The first playthrough, when choice_seed = 12, allows the reader to go to the market or the castle, then talk to the stable girl or talk to the priest.

After one playthrough you could give your reader a new seed code: ‘21’. Now when *input_num is used at the start of the game, you can vary significant parts of the story.

*input_number choice_seed 11 22

(This input-number allows either 11 or 12 or 21 or 22 to be inputted). The reader inputs the new code you gave them ‘21’

Now the reader is given the choice to go to the tournament, or go to the prison on page 1. Then on page 2, they have the choice to talk to the squire, or talk to the arms master.

Note: if you use this method you might just have given yourself twice as much story to write, but 85% of your players (who won’t reread), will never actually see it.


I’d suggest rewriting/redesigning your game.

You shouldn’t be giving an unsatisfactory ending. You shouldn’t be providing unsatisfying choices.

There shouldn’t be right or wrong choices. You should try to ensure that each path is as fun as the others.

Have a read of COG Game Design Guidelines particularly the section on choices and on Victory Design and Endings.

Every ending should be awesome, even if it’s a failure or a tragedy. There should be something dramatic and satisfying about every ending.

In Choice of the Dragon, the PC can get killed early…by getting struck down as divine retribution for setting themselves up as a false deity.
In Psy High, the PC can get arrested, but have the awesomeness of knowing that they’ve destroyed the magical mind-control device.
In Choice of Zombies, the PC can succumb to the zombie hordes, but have the awesomeness of knowing that they were able to not only save their foster child, but also get word out about how to fight the zombies.
In Hollywood Visionary, the PC’s movie can flop at the box office, but get the awesomeness of having it turn into a cult classic


Thank you for the random number code. I think I will be able to use that for my purpose. Looking at the saving code though, I don’t think it would really accomplish what I require. I probably could make it work, but the number of numbers I’d have to transfer over would get rather ridiculous. A lot of things in the game would be controlled by independent variables, each of which would have to be inputted by the player every single time. If possible, I’d rather keep these values hidden from the player, especially at first as I want them to realize the story is changing as they play through it the second time. Is this possible?

Thinking about it, I guess I am trying to create stats that persist across multiple playthroughs of the game, never being reset but altered each time by the player’s actions in the new version of the game.

I think you misunderstand what I mean. I’m not trying to make a right and wrong ending. I’m not trying to make one path the “right” path to travel. Every path that you take is going to be (hopefully) equally engaging, but I am trying to turn endings from actual resolutions into parts of the story. I’m not sure how to explain it, but games like the Stanley Parable and to an extent Undertale (I can’t think of any examples I’ve seen from here) have done it much better than I probably will. The endings are going to be engaging, but at least a large portion of them wont be endings in the traditional sense. The player’s character will experience a life each time, but the majority of lives do not end in what would be considered satisfactory circumstances for the player’s character. The player (if I’m up to the task of converting this idea into a story) should begin to understand what is happening to this character over multiple playthroughs; reaching endings that, while inciting the player’s curiosity about the total story and hopefully engaging them, lack the traditional resolution present in an ending. In a sense, these are not endings for the player, but merely another chapter in the story. I hope that made what I am trying to do a little clearer.

This is why I need to be able to alter the game in subtle ways as the story is replayed. If you have to play the story multiple times to truly reach its resolution, its end, it will be hard to bear the same scenes and choices that were there every single time. The game needs to feel like it is reacting to you, almost conversing with the player throughout their playthroughs. To do this I need the game to remember the previous runs so that it can know how the player is playing and is capable of responding correctly. I probably will have to write a lot of story that no player will ever see, just to ensure that they never see exactly the same thing twice and get bored with the game due to its repetitive nature.

The ending that is going to be the hardest ending to write comes soon after the first choice in the game. The whole point of this unusually short storyline is to shock the player into the mindset of endings not really being endings that is necessary for the game to work (hopefully on the first playthrough). Without this shock delivered early in the total experience, the player will not think of this in the mindset required and will simply get fed up with the actual game and leave, thinking that it is to hard to “win” when they haven’t even gotten to the end yet. Once I have that written, I can hopefully show what I am trying to do more clearly than I can explain it. Thank you for the advice though. My worst apprehension about this game is going to be writing its “false” endings to ensure that they are still engaging while making the player not feel as if it is an ending. I’ll take a look at that link and see if it can help with that.


There’s a few ways to do that.

Have you played Paradox Factor? If not I’d suggest playing it, then looking at the code and seeing if its style of repeat ing would work for you.

Second method is coding up a save system that tracks previous choices and having the player enter the save password each time they start.

Third is use achievements, since they’re persistent. There’s discussion of how they can be used elsewhere on the forum but I don’t have a link immediately to hand.



If possible I’d rather not do a save code, as that would quickly balloon out of hand with the number of things that I need to be able to do. Achievements might be able to work, but the problem is that I need to be able to be able to pass more than booleans over every playthrough. I need to be able to acknowledge repetition of an action as well as its first completion. For example, early in the game I’m planning on having a radio or TV, showing a program that is based upon the previous actions of the player. It will mainly focus on the run directly prior, but if the user does the exact same choices three times in a row I want the game to be able to comment on that (subtly of course).

Would I just have to make my game not end? I probably could just loop back to the first scene of the game after an ending (assuming that this allows you to keep the variables that you’ve already created), but then isn’t there issues with closing the game and saving your progress?

Paradox Factor appears rather interesting from its concept alone (I hope to buy it soon and get a better view of how it looks from a reader’s perspective). It seems like a similar concept, though maybe not taken to the extreme I am planning to take this too. However, I’m not entire sure how I can view the source code to see how he implemented it.


This is what I was going to suggest, and I agree that Paradox Factor is a terrific example of gameplay similar to what you describe. If you want people to keep playing with variations until they reach a satisfactory ending, don’t use the *ending command until they get there…

As for how to view the source code, scroll down to the bottom of this thread for the latest advice:

Not if it’s published (HG or COG).


The short story is that you can check achievements from previous playthroughs, although that is entirely unidirectional.

As for making an ‘unending’ game. I recommend strongly against it. The *ending command is important in cleaning old information and helping the game rank higher in the various app stores (with the prompts to share and rate).


Thank you @Havenstone for the link and both you and @RETowers for advice.

I’ll have to take a look at Pardox Factor and some of its code, because as I hear more and more about it, it does sound like it has very similar gameplay. It will be very interesting to see how the author overcame the problems I have been having as I started to work on this game. There’s been so many features in ChoiceScript, like achievements, that looked like they should work and then had some small flaw that made them unusable for my needs.

I do agree that I probably should just loop back to the beginning of the game after the, for lack of a better term, “wrong” endings. I wish I could end the game at each one, but from the documentation and what help I’ve been given here, its pretty clear that ending the game at one of these endings would make it impossible for me to continue it in the way I envision. I worry that I many not be able to have an ending at all as even what endings might be considered good should (at least in theory) inspire the player to want to answer more questions which requires me to keep the data about their previous playthroughs so that the experience doesn’t suddenly fall flat as everything that has been interacting with them gets suddenly reset.

I think that you are right, @RETowers, that this would probably end up hurting my game. If it really comes to it though, I probably could use the *link command to make a substitute ending screen between each restart. I would rather not, as it would break the flow, but I probably can find some way to squeeze in something without breaking the immersion. Possibly, as I am already having places where I am planning to have random commercials, snippets of conversation, etc., I could have a chance of actual requests of the player (share this game, go see our website. . .) to appear in those spots. Done sparingly I could see it working, but I would have to play it for myself before deciding if it works for the feel of game I am trying to create. If it doesn’t I’ll probably have to resort to a substitute ending screen which has the same affect as normal except with links instead of choices.