Choice rewind system

Howdy. Happy New Year. Been a while since my last post. Hope everyone is doing well.

If someone already solved this problem, I didn’t find the solution when I searched the forum topics, and it took me a few hours to figure this out; hopefully someone finds this helpful. Very happy to get feedback or improvements.

I was playing around with CS and found what I think is a coding solution to enable choice-by-choice “rewind” (or arbitrary frequency). I put this in my code for testing, but I think it could also be used as a general player facing feature or creatively.

Basically, this code allows for saving a checkpoint before every choice that does not get overwritten until after the next choice.

If you just put a *save_checkpoint rewind before every choice, by the time the player (or tester) sees the next choice, the checkpoint will be overwritten.

This is my alternative:

in startup.txt:

*comment "jrc" is "just restored checkpoint"
*create jrc_rewind false
*create jrc_rewindaux false
*create jrc_rewindreturn false
*create checkpoint_exclusions "jrc_rewind jrc_rewindaux jrc_rewindreturn"

in a subroutine file (mine is called “xsubr” for example):

*label rewind_highside

*comment This subroutine sets the location to which the rewind option will deliver the player. Must be paired with rewind_lowside on the low side of the intervening content (usually a *choice or *fake_choice block).

*set jrc_rewindaux false
*save_checkpoint rewindaux
*if (jrc_rewindaux)
   *set jrc_rewind false
   *save_checkpoint rewind
   *if not(jrc_rewind)
   *set jrc_rewindreturn true
   	*restore_checkpoint rewindreturn
*return
*label rewind_lowside

*comment This subroutine causes the preceding rewind checkpoint to be saved. Must be paired with rewind_highside on the high side of the intervening content (usually a *choice or *fake_choice block).

*set jrc_rewindreturn false	
*save_checkpoint rewindreturn
*if not(jrc_rewindreturn)
	*set jrc_rewindaux true	
	*restore_checkpoint rewindaux
*return

Then, at the beginning flow of the game (e.g. at the end of startup.txt, at the beginning of your first scene, or otherwise just before calling either subroutine) save all three checkpoints using:

*save_checkpoint rewind
*save_checkpoint rewindaux
*save_checkpoint rewindrestore

Saving the checkpoints before calling the subroutines makes them work the way that you’d expect, if they’re not saved before, you will get an error that says that there’s no checkpoint saved in rewindrestore (i think I know why this happens, but it’s not relevant here, as long as you save all three checkpoints before calling the subroutines, it will work).

And finally, in the main flow of the game, call the rewind_highside subroutine before a *choice or *fake_choice block; then call the rewind_lowside subroutine following the *fake_choice block or as part of the results of each choice in the choice block.

For example using *fake_choice:

*gosub_scene xsubr rewind_highside

Here's the situation.

Which choice will you make?

*fake_choice
	#Choice 1
		Text 1
	#Choice N
		Text N
*gosub_scene xsubr rewind_lowside

For example using *choice:

*gosub_scene xsubr rewind_highside

Here's the situation

Which choice will you make?
*choice
	#Choice 1
		*gosub_scene xsubr rewind_lowside
		*goto result 1
	#Choice N
		*gosub_scene xsubr rewind_lowside
		*goto result N

Then call the rewind checkpoint at any time (outside of the rewind subroutines) using *restore_checkpoint rewind

Let me know if you have thoughts or questions :slight_smile:

Edits: I accidentally hit post then forgot to name the topic. Then I forgot to explain how to restore the checkpoint.

9 Likes

i am SUPER interested in using this for playtesting my current project, but i think i’m unfamiliar with some of the coding techniques :,) does this code use stuff like arrays or whatever else? or i guess, can i ask i what tools are you using, specifically on the part:

*create checkpoint_exclusions “jrc_rewind jrc_rewindaux jrc_rewindreturn”

i’ll read up on the CS documentation to get a better understanding of what tools you’re using before coming back to discuss more. it looks super cool and helpful though!! i’ve been wondering about finding a way to rewind choices in serve.command instead of having to update all my files on my cogdemos test gams.

the *create checkpoint_exclusions "" code is creating a special variable checkpoint_exclusions and assigning the value "string1 string2 string3 stringN" (which is an array of strings, yes which is just a string, itself). I’m not sure if I understand the question about what tools I’m using. This is a part of normal Choicescript, to the best of my understanding.

Advanced Choicescript - Choice of Games LLC

This is the docs page that discusses it. I’m using the VS Code extension built in Run Game function to test the functionality. I believe that CSIDE doesn’t currently support checkpoints, but I may be wrong about that (i haven’t gotten it to work using CSIDE).

New Choicescript extension for VS Code (2.0 now runs games!) - Game Development - Choice of Games Forum

ChoiceScript Language - Visual Studio Marketplace\

The docs specify that this variable checkpoint_exclusions is specifically checked when using the *restore_chekpoint command (variables whose names appear as strings in that array as substrings in that string are not reverted to their previous value when a checkpoint is restored).

Once you list the variables that shouldn’t get reset, you don’t have to do any array operations on the checkpoint_exclusions variable for this application (but I think you could for other purposes using *set checkpoint_exclusions in other parts of the game).

Also, note that I’m updating the original post because I forgot to mention something important (that you have to save all three checkpoints rewind, rewindaux, rewindrestore before using the subroutines).

Does that answer the question?

I revised my previous answer after realizing it was wrong. there are no arrays in the code i described. my bad.