Ren'Py Variables not saving [SOLVED]

LunaLena

Newbie
Game Developer
Jan 25, 2020
30
55
Hi.
I'm making a game where there is a map navigation system, and where you can have different stats showed in it.
Here is the code of my variables file:
You don't have permission to view the spoiler content. Log in or register now.

Here is the map UI file:
You don't have permission to view the spoiler content. Log in or register now.

So the default values of "day" and "money" for example (but it's the same issue for every other ones) are respectively "0" and "$2000".
After the tutorial, they are set to "1" and "$2100", and if you save and load at this point, it will work, but if you try to play and save when it is showed for example day "3" and "$2800", when you will load that save they will be reset to "1" and "$2100", which means they are saved at some point, but something prevent them from being saved after the tutorial.
Here is the code of one action you can do with tutorial being active and without tutorial being active.

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,607
2,256
I very much doubt it's a save problem, but I understand why you might think that.

I assume you are still working on the game within the RenPy SDK... Launching the game via the [LAUNCH] button on the RenPy launcher? As long as that's true... you should still be able to use the RenPy console without doing anything extra.

So start your game, play to the point where you KNOW day = 0 and money = 2000 and then open the console [SHIFT+O].

Put in these two commands:
Python:
watch day
watch money

Then either use the exit command, or just press <ESC> to return to the game.

This will show those variables in real time while you play through your game. (Use unwatch to remove variables from the watch list). Continue to test your game and keep an eye on the watch list values any time you expect the values to change. If they don't change (which is my guess)... then it's probably that your if statements aren't quite right.

This is a quick off the cuff answer to avoid me going on a deep dive of your code. If you test stuff with the watch list switched on and things aren't how I'm presuming... feel free to come back and say that and I'll take a further look.
 

LunaLena

Newbie
Game Developer
Jan 25, 2020
30
55
I very much doubt it's a save problem, but I understand why you might think that.

I assume you are still working on the game within the RenPy SDK... Launching the game via the [LAUNCH] button on the RenPy launcher? As long as that's true... you should still be able to use the RenPy console without doing anything extra.

So start your game, play to the point where you KNOW day = 0 and money = 2000 and then open the console [SHIFT+O].

Put in these two commands:
Python:
watch day
watch money

Then either use the exit command, or just press <ESC> to return to the game.

This will show those variables in real time while you play through your game. (Use unwatch to remove variables from the watch list). Continue to test your game and keep an eye on the watch list values any time you expect the values to change. If they don't change (which is my guess)... then it's probably that your if statements aren't quite right.

This is a quick off the cuff answer to avoid me going on a deep dive of your code. If you test stuff with the watch list switched on and things aren't how I'm presuming... feel free to come back and say that and I'll take a further look.
No but they DO change, they are shown properly, but whenever I save and try to load my game, they are being reset.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
Have you customized the screen file_slots(): ?

Are you using label after_load: for anything?
 

LunaLena

Newbie
Game Developer
Jan 25, 2020
30
55
Nope, I haven't touched the screen file_slots nor anything.
And I don't use the after_load label.
Some people said it's maybe the screens but i don't know why it would be the screens since they're the same ones used with the tutorial too.

In case you didn't understand, the values have been saved once after the tutorial, but they do not save afterwards.

Here's two screenshots with the console opened. First screenshot after playing a bit, second screenshot after saving the game and trying to load it. (The "Skipping" label showing on top left corner is because I use CTRL + Mouse5 to screenshot xD)
Screenshot_11.png Screenshot_12.png
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
Was just checking. It was possible that if you had altered the screen file_slots(): that you had inadvertently changed things so that it loaded the save file from slot 1, even though you click on slot 2 for example.

Likewise, using label after_load: could mean that despite the values being correct in the save file itself, it was being overwritten as the file was loaded.

But if you haven't done either... then neither is likely.

I did look briefly at your code... and nothing looks wrong... at least with the small sections you've included. Will take a longer look shortly.
 

LunaLena

Newbie
Game Developer
Jan 25, 2020
30
55
I fixed my issue!

I don't know why I did that (probably too tired this morning, it was 3AM when I stopped working to go to bed xD) but my imagebuttons were not making a Jump to my game_home label but a ShowMenu, so the variables were indeed showed properly for the screens, but they were not saved by the game itself. If you look at my "mapUI" code you will see it was indeed a Jump for the tutorial and not a Jump when the tutorial was over. (The others ShowMenu('save') are just to setup my different actions xD)
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
Okay. Glad you're sorted.

The imagebutton ... action ShowMenu("save") did have me a bit confused, I just assumed it was an unusual placeholder. Plus I was having to work around the fact I didn't have labels like tuto_day1 and navigation... plus all the UI images that I was also missing.

btw. a better placeholder action would be action NullAction().

But it did seem to be doing things correctly.

The action ShowMenu("game_home") still looks off to me - but only because RenPy tends to use those style screens for preferences and other RenPy UI reasons, accessible from either the game menu or main menu - rather than game/developer UI reasons, accessible as the game is being played. But if you are happy it's working how you want... who am I to say differently.
 
Last edited:

LunaLena

Newbie
Game Developer
Jan 25, 2020
30
55
Okay. Glad you're sorted.

The imagebutton ... action ShowMenu("save") did have me a bit confused, I just assumed it was an unusual placeholder. Plus I was having to work around the fact I didn't have labels like [icode]tuto_day1 and navigation... plus all the UI images that I was also missing.

But it did seem to be doing things correctly.

The action ShowMenu("game_home") still looks off to me - but only because RenPy tends to use those style screens for preferences and other RenPy UI reasons, accessible from either the game menu or main menu - rather than game/developer UI reasons, accessible as the game is being played. But if you are happy it's working how you want... who am I to say differently.
The ShowMenu('game_home') is an error, it was Jump('game_home') that made it work.
I think I just forgot to edit the action because by default I had ShowMenu('save') as a placeholder.