Before I go and create a test game to make the bug(?) reproducible for others, I'll first just throw the general problem out here, and maybe somebody can tell me why it is the way it is, and maybe even offer a workaround?
Pseudocode:
Code: Select all
python init:
class Obj(object):
def __init__(self,name):
self.name=name
#probably needs more stuff here so it can't be pickled
a_hash={"key":Obj("an example")}
screen testscreen():
$ obj=a_hash["key"]
vbox:
text obj.name
label start:
"before"
call screen testscreen
"after"
So long as the game does not show testscreen, the game can be saved and loaded normally. That holds even after testscreen was shown (and left again).
However, if you try to save while testscreen is visible, you get PicklingError: Can't pickle ...: it's not the same object as ...
I haven't tested the exact pseudocode above, but if I comment out the lines assigning and then using the equivalent of <obj> in my game code, saving works.
-> a_hash does not get saved, because the variable gets set during initialization and does not change afterwards (even though the hash content might). Thus a_hash does not need to work with pickle.
So the general question here is, why does the pickling code even look at the screen variable <obj> in the first place? (And it must be a screen variable - if I was accidently writing to store, saving wouldn't work after leaving the screen.)
After all, when I load the game, it starts at the beginning of the current interaction, which is "call screen testscreen", so any screen variables will be calculated anew anyway!
Does anybody know why Ren'Py tries to save <obj>?
Or should the above code actually work and saving be possible while testscreen is shown? If so, I'll make a real testcase out of it.
My current plan is to change my code to do
Code: Select all
$ key="key"
vbox:
text a_hash[key].name