Thank you!
I found this thread mere minutes after effectively discovering the same thing albeit symptomatically
- this thread at least confirms WHY it was not working
- i.e. use of class variables, not being saved due to limitations in pickle, thx PyTom!
In my specific case, using Ren'Py v6.99.3, I was having no luck getting game state to correctly re-load two variables
(both 8 element lists of integers)
I should add I also tried other versions 6.17, 6.18 for SDL vs SDL2-related functionality, but this variable save/load is not a version specific issue.
After reading the doco numerous times, specifically
http://www.renpy.org/doc/html/persistent.html
I knew I did not want persistant or multipersistant variables, these had to be save-specific.
and then after
http://www.renpy.org/doc/html/save_load_rollback.html
I gathered that the key was to init any variables I wanted to be saved,
in or after the label start:
NOT in an init: or init python: block
Since I was still not having much success,
I started on a few red herrings:
first related to SetVariable and SetScreenVariable,
which as it turns out are separate from non-screen variables,
and which cannot be set outside of a screen language action anyway
When I saw this thread:
http://lemmasoft.renai.us/forums/viewto ... le#p370214
I tried to set up a basic class even without an __init__ constructor (my bad)
like so:
Code: Select all
init python:
##############################################################################
# bodypart.ix - list - item index for each bodypart
# bodypart.co - list - rgb index for each bodypart
class bodypart:
ix=[1]*8
co=[0]*8
which I then instantiated from label start:
Even after I had moved the variable initialisation to label start:
no luck.
I was becoming convinced that my variables (if they were even being saved at all)
were being magically overwritten by some init code at game reload
I then tried to set up some code which used try-except NameError blocks in a label after_load:
such that the class would only be instantiated once on game start, and never on a reload
That was also ineffective in terms of variable reloading,
although debug/tracing showed that the try-except logic was working correctly.
I then became paranoid about exactly was meant by
'When a game is loaded, the state of the game is reset (using the rollback system described below) to the state of the game when the current statement began executing.'
thinking perhaps that python statements were not being treated as save-points
even when they were single $ lines not python: blocks
So I littered my code with unnecessary RenPy narration style text statements to pad out the code between variable assignments.
Still no luck.
I was not clear as to exactly what was meant by this in the save_load_rollback doco.
It appears to contain a typo/redundancy of the word 'is' (or maybe missing 'ring' after 'refer'?)
which obfuscates the meaning somewhat:
Python variables that are not changed before the game begins will not be saved. This can be a major problem if a variable that is saved and one that is refer to the same object. (Alias the object.)
So I then took a leaf from Philat & Trooper6' posts in this thread:
http://lemmasoft.renai.us/forums/viewto ... le#p370309
and went back to basics using a simple var definition after label start, incrementing it after each call screen iteration in the main game loop,
and I found that the simple variable WAS being saved and reloaded correctly every time,
yet my class variables were not.
I tried this:
which seemed to work only when I played the game, changed some values, then reloaded from within the running game.
If I quit and then reloaded rather than start, it still reloaded the initial values not the updated ones.
Finally, I bit the bullet, dropped the class definition and went with a simple definition after label start:
Code: Select all
label start:
python:
bpix=[1]*8
bpco=[0]*8
Et Voila, perfection. Save & Reload now picked up the correct values.
So for now, lesson learned I think, K.I.S.S.
(or at least, do not rely on class variables being saved correctly)
So anyway, big thanks again,
These forums are a lifeline, I would be absolutely lost without them and contributions from PyTom and the veterans!
- the doco,wiki and tutorial code notwithstanding