In blender, you can store strings, integers, floats, timers, and boolean operators in an object by creating a property in its logic. However, you cannot store lists and dictionaries. I am creating a class, and I can't store a dictionary or a list as you cannot create this in an object's properties. The only method I can seem to think of is the following:
- Have a module with the properties you want to save. For this example, I will refer to this module as
class_properties.py
. - When creating the class, refer to
class_properties.py
for properties. - In the module that has the class, use
import imp
andimp.reload(class_properties)
in order to always reload the module and get the newest values.
Sure, this may work, but it's messy and nonsensical. With all my properties in my class, I can refer to the game object's properties. For example, I can do the following:
class Player(object):
def __init__(self, game_object):
self.game_object = game_object
self.health = self.game_object["health"]
But if I have a dictionary, I cannot do the following:
class Player(object):
def __init__(self, game_object):
self.game_object = game_object
self.health = self.game_object["health"]
self.dictionary = dictionary{}
Why can't I do this? Well, the reason I used self.health = self.game_object["health"]
is so I can update the player's game object's property health
and have the class always have the updated value. If I use self.dictionary = dictionary{}
, I would not be able to change dictionary according to the current scenario as self.dictionary
would always be dictionary{}
without anything in it as it always gets reset, for the __init__
function will always be called.
In other words, I need to have a dictionary in a game object's properties. I can store, for example, integers, in a game object's properties, so integers will always be stored. However, I cannot store a dictionary, so the class will never have the correct dictionary as it always gets reset in the __init__
function.
How can I store a dictionary & a list in a game object the same way I would store, for example, an integer? Thanks.