BGE PyAPI support for subclassing any BGE game type from python, scripters define extra functions on gameObjects.
Adding a UI to set the type on startup can be added easily. # ---- class myPlayer(GameTypes.KX_GameObject): def die(self): # ... do stuff ... self.endObject() # make an instance player = myPlayer(gameOb) # gameOb is made invalid now. player.die() # ---- One limitation (which could also be an advantage), is making the subclass instance will return that subclass everywhere, you cant have 2 different subclasses of the same BGE data at once.
This commit is contained in:
@@ -204,13 +204,13 @@ static long pyrna_struct_hash( BPy_StructRNA * self )
|
||||
/* use our own dealloc so we can free a property if we use one */
|
||||
static void pyrna_struct_dealloc( BPy_StructRNA * self )
|
||||
{
|
||||
/* Note!! for some weired reason calling PyObject_DEL() directly crashes blender! */
|
||||
if (self->freeptr && self->ptr.data) {
|
||||
IDP_FreeProperty(self->ptr.data);
|
||||
MEM_freeN(self->ptr.data);
|
||||
self->ptr.data= NULL;
|
||||
}
|
||||
|
||||
/* Note, for subclassed PyObjects we cant just call PyObject_DEL() directly or it will crash */
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user