Save and load system, handling MC died

I have followed the excellent advice given here on creating a load and save system:

I haven’t tested it yet.

In my game it is possible to die. The coding for this is the same throughout, the code goes to a scene called youdied, there is a pic and then *ending

Now, at this point I am looking to add a Load option so the MC can choose to replay the chapter

The problem I am having is, the player can have arrived here at any point in the game so there is no way for the code to know where to return them to.

I am thinking therefore to change how I have coded deaths in the game. I am thinking to remove the youdied scene and replace it with a go sub? This would mean the death is “contained” within the scene and it would be easier to start the scene over?

Before I do this can I please ask if this is the optimum solution?

1 Like

Not sure if this would work but you could save the last checkpoint *label on a variable.

*set last_checkpoint "chapter3_mid"

Or something like that, and then when you use *goto you can use valueOf (also known as *gotoref) to *goto what’s inside the last_checkpoint variable.

*goto {last_checkpoint}

or

*gotoref last_checkpoint

And then somewhere in your game you would have a

*label chapter3_mid

Now that I think about it, they might also be in different files (scenes), so you might have to save the file name on a variable too.

*set last_scene "chapter3"

And I think this could work:

*goto_scene {last_scene} {last_checkpoint}

You might have to do some tests to see if that works, I don’t remember if that’s exactly how you use it.

2 Likes

With my basic skill with choicescript, i’m gonna propose you that but i’m not sure if it will work but hey, it cost nothing trying? :relaxed:
Firstly i would create a scene named save.txt and an variable caled chapter. Each time i reach a new chapter, i will set the variable chapter to one number like that:

Chapter1
*set chapter 1

Chapter2
*set chapter 2

Chapter3
*set chapter3

etc....

So, every time that the player die, i will implement a choice like that

*choice
  #Reload from current chapter
    *goto_scene save
  #End or beginning the game
    *ending
      Or
    *goto_scene beginning

So, the code in the save file would go like that.

*if chapter = 1
  *goto_scene chap1
*if chapter = 2
  *goto_scene chap2
*if chapter = 3
  *goto_scene chap3

etc...

I hope my basic understanding of choicescript will help :relaxed:

Many thanks for the input, here is what I am struggling with at the moment:

Let’s say the player gets to chapter 3 and thinks - OK, I’ll save here and explore these paths.
They then play on for a few chapters and die

I need to make sure they pick up from where they last saved. IE back to chapter 3 in this example

If I am not careful they will be able to restart at chapter 3 with inventory etc from chapter 4, 5, 6 etc

Here is an excellently helpful reply to my previous post. This would solve every problem Except a player wanting to save at chapter 1 , go through 2, 3, 4 and die and then start again at chapter 1

Also, that the app does not have a save system inbuilt?

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

Jonnysaxc:

where does it go? Into cache?

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

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

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?
*choice
	#Restart
		*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.

Well, following my examples, the game will save itself without the players is consent but they will able to come back from the last chapter nonetheless.

If you want to make sure that they don’t go back to previous chapters with items of chapter 4,5,6 etc then you just have to set these item’s variable to null like that.

*if chapter = 2
  *set itemsFromChap3 ""
  *set itemsFromChap4 ""
  *set itemsFromChap5 ""
  *goto_scene chap2

etc...

I’m just a basic coder lol. Every time i try to find the easiest way to do the trick :joy:

But now that I think about it if the game goes back to the chapter where the reader saved, logicaly speaking the system will consider everything after that chapter as null, right?

Don’t ask me lol!

I am slowly absorbing the kind information and tips. Because the game is working (a miracle basically!) I don’t want to change anything major that might break it. BUT, it has to have a save system so I will have to take the plunge at some point

1 Like

:joy: OK. Maybe you should browse trough the choicescript wiki and see if you can find anything that might help you.

Been drinking tea and thinking more about this
Maybe I make each chapter as a variable as well like this:
*create club false
*create boat false

and so on

then I follow the save and load variable instructions already provided

and as the player moves through the game I set chapters false and true as relevant like this:
when in club

*set club true

when on boat
*set club false
*set boat true

Then I guess I need a way to return to that, which could be:?

*if (club = true)
*goto_scene club

*if (boat = true)
*goto_scene boat

and so on

more tea needed!

Here is my current thinking then:

Take this code

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

and change to this (not formatted)

Onto the next chapter or start over?
*choice
#Restart
*gosub_scene gamesave load
*if (chapter = 1)
*goto_scene chapter1

etc

#Onto chapter 3
	*goto_scene chapter3

Edit - I will also need to think about players that arrive at the youdied page and have NOT saved anything

Having the save system this way might be the easiest, and the *if (chapter = 1) line should work. Having played the game, though, what about when the player reaches the central building but they do not have the knowledge they need? If the player restarts the chapter they still won’t have the required variables set – and they will always end up on the youdied page.

In that case you may want to heavily hint on that youdied page that they need to restart from the beginning/replay certain chapters to find that required knowledge. Or in instant win mode (or in both modes) you could even create saves for the chapters where those variables are set without even asking the player, and so when they reach the central building and die they can head back to the earliest chapter with the missing knowledge. That’ll require more save/load variables, though.

Did my method work?

Many thanks - I am going to try today in light of all the kind advice
Right now I think it is going to be too complex for me
Because of this I am going to add all the new code between a *comment so if I can’t do it I know what to delete

OK, we have progress of sorts!

Good news, I was able to make an option to save the game and to successfully load back to a save position when dead

I then started to build in the second chapter and started getting non-existent variable errors

Looking into this it is because the next scenefile has temporary variables in it

Now, I think this is a big problem because I use a temp variable of bullet roll and bullet damage and don’t think they can be in the startup file?

Edit- I have copied the temp files and moved them so they are first when the code jumps back to the scene - phew!

the system seems to be working, I have successfully loaded and saved progress including saving at the end of the first chapter and loading this save 2 chapters later
Thanks Everyone!

To implement this system is going to take me a while, after I have done this I will add a hint system to the youdied page. There are a number of things critical to winning the game, I will make a system to randomly hint at one of these on each death if the player chooses to have a hint

2 Likes

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