- Feb 19, 2023
- 71
- 38
I have issues in my game because data (variables who are declare with 'default' and change while the player progress) are not saved correctly. Yesterday someone introduce to me the concept of 'renpy.retain_after_load()' but calling it right before calling a screen or after cause the same issue. I've made a test project to illustrate how I currently code my game and how to reproduce the issue. Apparently renpy is not able to store data after the first level of an object or perhaps there is something that I've missed ^^
Here is the code to reproduce :
Here is the code to reproduce :
Code:
init python:
class MySubCustomObject:
subvalue1 = 1
subvalue2 = "init sub value"
def changeSubValue(self):
self.subvalue2 = "new sub value"
class MyCustomObject:
value1 = 1
value2 = "init value"
subValue = MySubCustomObject()
def changeValue(self):
self.value2 = "new value"
def preventScreenPredictionAction1():
MyCustomObjectPointer.value1 = 2
MyCustomObjectPointer.changeValue()
MyCustomObjectPointer.subValue.subvalue1 = 2
MyCustomObjectPointer.subValue.changeSubValue()
renpy.hide_screen("QuickMenuActionScreen")
renpy.jump("step2")
default MyCustomObjectPointer = MyCustomObject()
define e = Character("Eileen")
label start:
scene bg room
show eileen happy
$ renpy.retain_after_load()
call screen QuickMenuActionScreen
label step2:
e "When you're here save and reload"
e "Now load the previous state and from console what's the value of my object ?"
e "'MyCustomObjectPointer.value1' = 2 (OK)"
e "'MyCustomObjectPointer.value2' = new value (OK)"
e "'MyCustomObjectPointer.subValue.subvalue1' = 1 (KO)"
e "'MyCustomObjectPointer.subValue.subvalue2' = init sub value (KO)"
return
screen QuickMenuActionScreen:
frame:
xsize 200
ysize 200
xpos 200
ypos 200
vbox:
xalign 1.0
ypos 45
textbutton "action1" action Function(preventScreenPredictionAction1)