How can I attach a class to an object in Blender Game Engine 2.79b using Python 3.6.5? I need the class to be attached to an object once it is initialized. What I mean by attached I mean class will be taking input and outputting corresponding control commands to the object once the game is initialized. The class is essentially going to be the bridge of communication between the object and the EMG signals. I am working on a Myoelectric-Computer Interface. There is a custom class written in Python using Pyserial to connect a device via Bluetooth through a communication port via serial port interface on my IBM PC-compatible computer. That is the class I am referring to.
What do you mean attached?
What is this class going to do?
What I mean by attached I mean class will be taking input and outputting corresponding control commands to the object once the game is initialized. The class is essentially going to be the bridge of communication between the object and the EMG signals.
I unfortunately lost my control dictionary, hence, I really need help with attaching this class to an object in the game.
Do you absolutely, positively need to make class and object inseparable from one another?
Then maybe you want to subclass KX_GameObject. That’s what I think I’d do, anyway.
If not just pass the object to the class at init and store the instance on a property;
class myClass:
def __init__(self, obj):
self.object = obj
def runFirst(cont):
obj = cont.owner
obj["property_name"] = myClass(obj)
def update(cont):
obj = cont.owner
self = obj["property_name"]
print(self.object)
>>>obj.name
Perhaps in this context you have reasons not to do this, can’t tell without code to read.
NINJAEDIT: typos. because I’m refined.