Ren'Py Ren'Py save question!

tomyboy06

Well-Known Member
Jul 31, 2017
1,079
20,841
Hello!

I am very new to the topic, so if my question is silly please forgive me.
I am trying to do a little story under RenPy. The story would consist of 5 parts. (0.1, 0.2, 0.3, 0.4, 1.0)
How can I get it to load the save under 0.1 in the 0.2 version.
Later, of course, I would like to achieve the same for the other versions.

I hope I managed to describe my question clearly.

Thanks in advance for your answers.
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,490
7,035
How can I get it to load the save under 0.1 in the 0.2 version.
First, what you have to realize is that the "save" basically saves the following:
  1. The state of all the variables in your game that were defined as of the time you made the save
  2. A list of which labels and which images the user has seen
  3. A record of the last (256?) lines that the user executed, including the line the user was on when they made the save.
(There's more, but those are the crucial ones for this discussion.) There's nothing in the save that's intrinsically tied to a specific version of your game, so as long as you follow a few simple rules, you won't have any problem.

Rule 1: For any variable you're going to create, set it up with a "default" statement. I usually do this in a separate file called variables.rpy but the location doesn't matter.
Code:
default number_of_times_he_drank_tea = 0
default did_he_go_to_the_market = False
Then, later in your code, you can change the variable to something else
Code:
    $ number_of_time_he_drank_tea +=1
    $ did_he_go_to_the_market = True
You CAN create variables on the fly just by doing
Code:
    $ some_variable_i_never_used_before = 2
but this can get you in trouble. (I'll avoid the paragraph-long description of why.) Just always use defaults.

Rule 2: Once you've put out the 0.1 version, be very very careful about going back and modifying 0.1 content in your 0.2 release. It's not that you can't do this - fixing spelling and grammar and things like that are no problem. But if, for example, you go back and put in a new choice in the 0.1 section, someone that has played through and done a save near the end of your 0.1 won't have gone through that code, so any variables you set in that choice won't have been set. There's a way around it, but avoiding it, if possible, is better.

Rule 3: When you get to the end of your 0.1 content, put something in that says "OK, you've reached the end, save now" before you dump them back to the main screen. This way, their save is positioned right at the end of the content they've played through, and when they load the save, they'll pick up exactly where they left off.

Now, you're probably going to say "But when I do the 0.2, I'll take out the line at the end of 0.1 that says "save now." What happens?" That's a very good question. Part of the reason that Ren'py "remembers" the last N lines that were executed as part of the save is that if the statement that was active when the player made the save has been removed, Ren'py can "back up," line by line, until it finds a matching line that IS in the 0.2, and then pick up from there. Works beautifully. (Nice piece of work by PyTom.)

Rule 4: Once you have started developing your game, do NOT delete any of the .rpyc files that Ren'py generates. You might think "oh, I want to force Ren'py to recompile from scratch." There's a "force recompile" button in the Ren'py console for that. Remember the "Ren'py remembers the last list of lines?" The way it does that is to assign an invisible, secret line number to each line in your .rpy file. That gets built into the .rpyc file. Ren'py is really smart about how it deals with line numbers, and it can handle you inserting extra lines in files or deleting a few lines. But if you delete the .rpyc files, Ren'py has to regenerate all that information, and it never comes out the same. (They aren't really "numbers" - I won't go into details.) So, if you delete a .rpyc file and Ren'py regenerates it, anybody that was in that file when they made their save can't restore that save.

That's about it. It's basically "if you don't do anything bad, it just works."
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
On a more mechanical level (on Windows, Mac and Linux), RenPy takes care of things by using a mix of a "saves" sub folder where you unpack the game AND a shared folder unique to the game.

So let's say you create a game called "Test Game".

Eventually, it will end up in a distribution file called "TestGame-1.0-pc" and will unpack to a folder of that same name.
So it perhaps ends up in D:\Games\TestGame-1.0-pc\.
The save files will be stored in the D:\Games\TestGame-1.0-pc\game\saves\ folder.

But on Windows, the save files will also saved in a folder similar to C:\Users\Username\AppData\Roaming\RenPy\TestGame-1536417966 (the number is semi randomly generated to make the whole name unique).
Similar shared folders are used by Mac and Linux, but obviously stored somewhere else.

If you released version 1.1 of your game, the shared save folder will still be TestGame-1536417966.

When you play a game, RenPy effectively merges both these sets of save folders together and uses the latest version of whatever files it finds. So even though the D:\Games\TestGame-1.1-pc\game\saves\ will likely be empty when you first play version 1.1... the TestGame-1536417966 shared folder will fill in the gaps from the 1.0 playthrough save files.

These things are controlled by your RenPy project within the options.rpy file.

Specifically by the lines:

define config.version = "1.0"
and
define config.save_directory = "TestGame-1536417966"

If you're planning to release 0.1, 0.2, 0.3, 0.4 and 1.0... then you'll want to start with config.version = "0.1" and update it each time you release the next version of your game. But don't change the config.save_directory unless you screw up your variables so badly that you want the next release of the game to effectively "start again from scratch" by using a new shared folder.
 

tomyboy06

Well-Known Member
Jul 31, 2017
1,079
20,841
Thank you for your replies.
79flavors the ones you suggested are fine. Everything is as you described. Version numbers save locations, save folders. I think there is no error here.

Rich's reply to Rule 2. Everything is in original condition nothing has been changed afterwards.

Rule 3. At the last frame it was indicated that the player should save.

Rule 4. Nothing has been deleted everything is in its original state.

My problem with Rule 1 is I don't really understand the example :(

So far I'm at the point of doing a save at the last frame of version 0.1.
I start version 0.2 the loading menu shows the save but always starts from the beginning.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
My problem with Rule 1 is I don't really understand the example

Rich is describing a problem some people have, because they copy games that were written a long time ago (or a newer game, which copied someone else, who copied someone else, who... etc. etc.)

The simplest way to think about it is that it is strongly advised to "create" each variable using a default statement. It doesn't matter where in the those default statements exists, as RenPy effectively scans the whole code before the game starts running and processes each of those statements immediately (and ignores them later) as the game starts.

The "old way" of doing it was to have an init: statement and have lines like $ my_var1 = 0 for each of your variables. There are some inherent problems doing it that way that means it works 99% of the time for simple games and will come back to bite you in the arse because you didn't use default. I only mention it, in case you see other people's code that do it that way.

Of course, it could be that your game doesn't use variables at all... and so your confusion is "what's a variable?"... to which my answer would be "don't worry about it".

So far I'm at the point of doing a save at the last frame of version 0.1.
I start version 0.2 the loading menu shows the save but always starts from the beginning.

It's difficult to diagnose without seeing the actual code. You say "last frame", but save points tend to be "last line of dialogue" (or maybe more accurately last true Renpy statement processed).

Your other work is PDF image sets from what I can see (I didn't look very hard)... Could it be that your "game" doesn't actually have any spoken dialogue in it? And is just a series of scene and pause statements?

Have you released v0.1 of your game? That is... could I download it to see if I can see anything obvious?

Because usually RenPy would only reset to the beginning if the structure of the game has changed too much since the *.rpyc files were originally created. It's why Rich's rule #4 exists.

When RenPy loads a save file, it uses a very technical cross reference (stored in the .rpyc files) of every line of code to try to figure out where it's up to. If you can imagine when you do a "rollback" while you're playing a game to step back through the game to an earlier point - the save system uses the same system. It tries to match things up to the latest line it knows the player saw, if it can't find that... it rolls back one statement and tries to find that... and keeps doing that until it either finds a match or gives up.

It's not quite this simple... but imagine a bit of code like:

Python:
    mc "phrase 1"      # id = 0001
    e "phase 2"        # id = 0002
    mc "phrase 3"      # id = 0003

If you save at "Phrase 2", the save file will record that you saved as "id #0002" (and the previous line was "id #0001").

If you then alter your code to be:

Python:
    mc "phrase 1"      # id = 0001
    m "a new phrase"   # id = 0004
    e "phase 2"        # id = 0002
    mc "phrase 3"      # id = 0003

The save file still works, even though "phrase 2" is the 3rd line of the code not the 2nd. (it's nowhere near this simple).

Likewise, if you changed or deleted the line "phrase 2", the save would still work, because it would rollback to "phrase 1" - because that was the line last shown to the player according to the save file's log.

But if you delete the .rpyc files or change the code so much that most/all of the unique id numbers for each line are unrecognizable between versions, then the "load" system will either get massively confused or revert to the start.


My last thought is that if the only person who's played v0.1 is yourself. Then don't worry about it. Save compatibility only really matters when there are save files out there in the world you have no control over.
 

tomyboy06

Well-Known Member
Jul 31, 2017
1,079
20,841
I will be honest! This is my first attempt and I'm completely new to the field.
That's all I really want to do, so that anyone who tries it doesn't have to start from scratch.
It would also be good to learn how to do it. So far I've learned by reading other people's code, but I've only gotten as far as formatting text.
Here is the 0.1 version
If you don't have any problems, could you take a look at it?

You don't have permission to view the spoiler content. Log in or register now.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Well, the good news is I was able to recreate your problem. But only by deleting the script.rpyc file (so RenPy would rebuild it from scratch).

Everything else I tried, worked how I described earlier.

I have two possible suggestions:

ONE:

Create a backup copy of your RenPy project folder (just in case my suggestion doesn't work).​
Download your own copy of version 0.1 (if you don't already have a copy somewhere on your PC).​
Open the ZIP file and extract the game/script.rpyc file. (ONLY the RPYC file).​
Copy the extracted script.rpyc file (0.1) and overwrite the file of the same name in your RenPy project folder (0.2).​
In effect, you're overwriting your 0.2 rpyc file with the 0.1 rpyc file.​
Under normal circumstances, this would be a very bad idea. But here, I think it will fix your save issue.​


TWO:

Edit the options.rpy file.​
Change the define config.save_directory = "JOHNTheWeek-1636480360" to something else. Pick any new number you like.​
Tell your players that 0.2 is incompatible with 0.1 saves.​
Cross your fingers the same doesn't happen when you start work on 0.3​
You can get away with this, as your 0.1 version is quite short and so shouldn't inconvenience players too much.​


I know you said you haven't deleted anything. But I can't see any other reason why it would behave in the way you're describing. Plus if solution #1 works, that pretty much confirms the diagnosis.

And now the bad news. If solution #1 does work, any saves you have from 0.2 will stop working for the same reason. Thankfully, since you are the only person who could have 0.2 version save files - it will only affect you and not your players. I suggest just accept it as "one of those things".
 
Last edited:

tomyboy06

Well-Known Member
Jul 31, 2017
1,079
20,841
Brilliant!!!
Your first suggestion really works and not just between 0.1-0.2.
I tried it with all five parts and the backups worked. I always had to copy over the previous version "script.rpyc". I have not been able to understand 100% the cause of the problem, but I am very happy with the result.
Thank you very much for your help.
I will post the story in FanArt soon.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Brilliant!!!
Your first suggestion really works and not just between 0.1-0.2.

Goodie.


I tried it with all five parts and the backups worked. I always had to copy over the previous version "script.rpyc". I have not been able to understand 100% the cause of the problem, but I am very happy with the result.

Erm.
Are you saying 0.1, 0.2, 0.3, 0.4 and 1.0 are already complete?

Also...
Are you saying you've copied the 0.1 file into all 5 versions?
Or are you saying you copied 0.1 -> 0.2, the original 0.2 -> 0.3, the original 0.3 -> 0.4 and 0.4 -> 1.0 ?


Thank you very much for your help.
I will post the story in FanArt soon.

Have 0.1 thru 0.4 been released to the public yet?

Because if you've already released them, this "fix" of mine could be fixing it for you, but breaking it for your players.
It really depends on the answers to my other questions.

1. Have all 5 versions been written?
2. Which versions have been released to the public?
3. Did you copy 0.1 to 0.2, 0.3, 0.4 and 1.0? (Yes/No)
4. Did you copy 0.1 to 0.2, but copy 0.2 to 0.3, etc? (Yes/No)

I suppose I should add one more...

5. Have any "public" players complained that the save files aren't working properly? (Yes/No)
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
I've just had a horrible thought, which is a complete lack of imagination on my part.
I'll send you a PM and explain here on the public forum if my guess turns out to be correct.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,284
I've just had a horrible thought, which is a complete lack of imagination on my part.
Is this related to the need to use the feature ? Because personally I had this kind of horrible thought.



This being said, did you guys forgot that there's a how-to you can refer to ? :D
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Thankfully my new worries were wrong.

After I realized all 5 chapters were already complete, it occurred to me that the author may have written each "chapter" of the game separately. With the 0.2 version of the game containing ONLY the 0.2 dialogue. Thankfully, it's written "normally"... with the each release of the game including all the releases that went before it. In effect, I was worried they'd inadvertently written 5 separate games rather than 5 incremental versions of the same game.

It's still possible that the 5 versions were developed in 5 separate RenPy project folders. But we're in "wild speculation territory" here.

On a practical level, since none of the chapters have been released yet and the author has the chance the rebuild the distribution files before sending them out - this save problem has only affected one person. Fixing it quietly in the background now therefore hopefully won't affect those players who eventually end up playing the game.

btw. The game (from what I've seen so far) is a pure kinetic novel - with no variables at all. So none some of the stuff we normally worry about with save files applies.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,284
Ok, you've the answer, detailed, to your question, and I pointed to the How-to that can help you deal with some specific problems. So, lets restart this, but from a none technical point of view this time.


I am very new to the topic, so if my question is silly please forgive me.
Firstly there's no silly questions, just possibly silly answers.
No one have an universal knowledge, and what seem obvious for someone can perfectly be a total mystery for someone else ; it all depend of the context. This apply even more when the subject is related to computers, because it still have an aura of magic for many people. In fact, it have it sometimes even for those who know perfectly the subject.

Just look at the answer you got, neither Rich nor 79flavors found your question silly. They both helped you with your problem, not only answering, but also guiding you.


I am trying to do a little story under RenPy. [...]
I get that it's the first time you're doing something like this. And I don't just mean making a little story, but also codding.


How can I get it to load the save under 0.1 in the 0.2 version.
Ren'Py have load/save screens, so don't you think that Ren'Py also know how to deal with the saving/loading process ?
I mean, when someone sell you a car, he will not tell you that it's in fact just some decorating prop, because there's no motor inside.
Note that this don't make your question silly. You don't know for sure because you're totally new to this, and for some reason (stress, some kind of fear, whatever), what feel logical do not feel obvious for you.


What lead to my own answer to your question:

Do not fear, and/or over stress, because of your project. Like a friend had the habit to say about her own game, "it's just a silly porn game".
This mean that it's just a side occupation. Whatever how important it can looks at your own eyes, it's not what define, nor decide, of your life. You have the right to fail at this, it's not a big deal and it doesn't mean that you worth nothing. The worse that can happen to you, is to discover that making Visual Novel isn't something for you, and there's really no shame to have because of this. Plus, unless your parents really named you "tomyboy06", no one except you will know this.

Writing an adult story/game should be a pleasing occupation. Even if you achieve to earn big money doing it, it's before everything else a hobbit you have, and it should stay like this. Sometimes you'll stress a little, because it's a delicate moment, but at the end of the week, it's the enjoyment you got that should be the dominant feeling.

Try to reach this state of mind, and you'll see, the next time you'll have a "silly question", you'll not ask "how is this working", but "Am I right to think that it works like that".
 
  • Like
Reactions: tomyboy06