Ren'Py Character definition and saves compatibility

lawfullame

Active Member
Game Developer
Aug 6, 2019
669
986
When I define characters, I use this way in the "definitions.rpy" file :

define jn = Character(("Jane"), color="#2eff00")

It happened to me today that when I added a new character to the definition section, loaded an old save and the character in Chapter 2 said something for the first time, Ren'Py displayed an error message saying that the speaker was not defined.

When I tried to start the game from the beginning instead of loading save, it worked.

When I tried to replicate the error, added another character and loaded the save, all went well and did not end in error.

How is it possible that sometimes adding a new character will cause an error in the old save and in another case not, even if I use the same method?
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
Anything created the define isn't stored in the save file.

define values are picked up at runtime only.

If I had to take a guess... I'd say a simple typo you haven't noticed yet. Or you already corrected without thinking about it.

You said you added another character... does the game still fail for the original (failing) character when you load that same save?

I'm sure it's unconnected, but I do wonder about that 2nd set of parenthesizes.
I'd expect your definition to be define jn = Character("Jane", color="#2eff00"). Without the extra brackets around the word "Jane".
 

lawfullame

Active Member
Game Developer
Aug 6, 2019
669
986
The behavior has changed without any change in the code. It didn't work once, and then it worked without changing anything in the code.
The only change was that I tried to start the game from the beginning but I didn't overwrite save.
When I loaded the original save later, it worked.
And if I add any new characters, it works.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
As long as it's working... I guess that's all that matters.

The thing is, you did change the code... you added another character - at which point you would have had to save the source code.

If you'd made a typo, saved it, corrected the typo and didn't save... then the game would have been running with the typo. You then look at the source (which is fine), scratch your head and then add another character and save the code. That new save also saves your typo correction and so when you run the game again, everything works.

I'm not saying that happened. But I've done that before now.

But either way, the answer to your original question is that no, adding a character shouldn't affect save files (because define).
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,228
If I had to take a guess... I'd say a simple typo you haven't noticed yet. Or you already corrected without thinking about it.
Another guess is that jn was already used. Therefore, when loading the save, it overwrite the newly added character and lead to the error he have.
 

lawfullame

Active Member
Game Developer
Aug 6, 2019
669
986
It was another character. I used jn only as example of my definiton here.

Anyway, sometimes it happens to me that Ren'py does strange things and restarting solves the problem.


However, it is quite rare.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,228
It was another character. I used jn only as example of my definiton here.
Which change absolutely nothing to what I said. It's just that in place of jn, it's another name that was already used by a variable.


Anyway, sometimes it happens to me that Ren'py does strange things and restarting solves the problem.
No, restarting never solves the problem, it just hide it ; bugs don't magically resolve by themselves, nor they magically appear from nowhere.
If a restart is enough, it can just be a design flaw, but the fact that you'll not trigger the bug again don't mean that some of your players will not. And, since you previously said that "the behavior has changed without any change in the code", chance are high that effectively some, if not many, of the players will trigger it.

Like 79flavors said, variables created with define aren't saved. Therefore, if their value change after a load, the most logical cause if that the variable was already used to store something else.
So, unless you removed the use of this variable, at some time the bug will appear again.
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,809
24,389
Like @79flavors said, variables created with define aren't saved.
just as side note, like any variable declared in an init block, also a defined variable is not being saved... unless you change it's value once. now it is treated as a regular variable, declared somewhere in the script, and it is now also part of the save file.