Abacus_Games
Newbie
- Dec 11, 2022
- 22
- 26
Hi,
I am trying to understand the expected behavior of created objects when you save your game in one version, then expand some functionality in the class the object is based on, release a new game version, load the previous saved game and see what works and what not.
My issue is that when you release a game in versions your code is a work in progress and evolve over time - you rarely get all attributes, properties and methods perfect from the beginning (at least not I that is not a professional coder in any way and just develop for fun in my spare time).
I have included a simple test snippet below and from that I have so far deducted that between releasing versions...
I guess you could use the label after_load to manually convert/upgrade/transfer objects or object data but that seems tedious - as for example I have hundreds of objects (actors, events, quests).
Is this understanding correct or am I missing something fundamental?
This thread seems to confirm this.
However, is there a way to add new methods to old objects as well - as is done with the attributes? How can I connect a new method to an old object - just by assigning a function?
Possibly, you could add a few "dummy" methods that is reserved for future use but you wouldn't be able to change their method names when calling them!? number of arguments!?
I am trying to understand the expected behavior of created objects when you save your game in one version, then expand some functionality in the class the object is based on, release a new game version, load the previous saved game and see what works and what not.
My issue is that when you release a game in versions your code is a work in progress and evolve over time - you rarely get all attributes, properties and methods perfect from the beginning (at least not I that is not a professional coder in any way and just develop for fun in my spare time).
I have included a simple test snippet below and from that I have so far deducted that between releasing versions...
- I can't add additional attributes as these are not recognized after loading a previous save
- I can't add additional methods as these are not recognized after loading a previous save
- I can change the code of properties (and probably methods as well although I haven't tested this yet) after loading a previous save
I guess you could use the label after_load to manually convert/upgrade/transfer objects or object data but that seems tedious - as for example I have hundreds of objects (actors, events, quests).
Is this understanding correct or am I missing something fundamental?
This thread seems to confirm this.
However, is there a way to add new methods to old objects as well - as is done with the attributes? How can I connect a new method to an old object - just by assigning a function?
Possibly, you could add a few "dummy" methods that is reserved for future use but you wouldn't be able to change their method names when calling them!? number of arguments!?
Python:
# Testing object attribute, property and method changes after save/load
default adam = Actor("Adam")
init python:
class Actor(store.object):
def __init__(self, name):
self.name = name
# self.age = 18
self.c = Character(name)
@property
def name(self):
# return "{color=#FF0000}" + self._name + "{/color}"
return self._name
@name.setter
def name(self, value):
self._name = value
# def get_age(self):
# return self.age
# Testing
label start:
adam.c "This is the start."
adam.c "Save the game here in version 1"
# Saving - Then change code (commenting), restart and load saved game
# Loading for version 2
adam.c "Is my name in red or not : [adam.name]."
adam.c "Do I have a default age?"
python:
try:
if adam.age:
renpy.say(adam.c, "I am [adam.age] years old")
except:
renpy.say(adam.c, "I don't have an age.")
# temp_age = adam.get_age()
# renpy.say(adam.c, "And I can't use added functions to get it (this will fail) : [temp_age] years old.")
adam.c "Now back to the menu."