[SOLVED] How to define persistable objects?
Posted: Wed Apr 03, 2024 10:11 pm
As the immortal Lloyd Bridges said in Airplane, looks like I picked the wrong week to quit drinking.
I started down a rathole trying to implement my own achievements system that would wrap the rudimentary Steam-flavored achievement class. Everything was working fine until I tried to persist my list of achievements.
I defined a class called Achievement that has a bunch of features like grouped achievements (achievements that are granted when all member achievements have been earned), flags for visibility of an achievement's title and description, alert and menu support, etc. I'm aware of a couple of commercially available add-ons but wanted to roll my own because, "How hard could it be?"
First, Ren'Py complains that my class can't be pickled. Being the trained developer that I am, I had implemented a class for the achievement itself, and a separate class to manage the achievement groups. Nope, the ancillary class must be hashable. So I implement a __hash__ method. Can't make that work, so I gave in and folded the goals object into Achievement itself. One simple class. Nope: my class "must support equality comparison." So I implemented an __eq__ method. Now, it's telling me "TypeError: Achievement is not safe for use in persistent." without any kind of hint as to why. Can someone point me in the right direction for clues? Or should I just bite the bullet and implement my own persistence method?
I started down a rathole trying to implement my own achievements system that would wrap the rudimentary Steam-flavored achievement class. Everything was working fine until I tried to persist my list of achievements.
I defined a class called Achievement that has a bunch of features like grouped achievements (achievements that are granted when all member achievements have been earned), flags for visibility of an achievement's title and description, alert and menu support, etc. I'm aware of a couple of commercially available add-ons but wanted to roll my own because, "How hard could it be?"
First, Ren'Py complains that my class can't be pickled. Being the trained developer that I am, I had implemented a class for the achievement itself, and a separate class to manage the achievement groups. Nope, the ancillary class must be hashable. So I implement a __hash__ method. Can't make that work, so I gave in and folded the goals object into Achievement itself. One simple class. Nope: my class "must support equality comparison." So I implemented an __eq__ method. Now, it's telling me "TypeError: Achievement is not safe for use in persistent." without any kind of hint as to why. Can someone point me in the right direction for clues? Or should I just bite the bullet and implement my own persistence method?