Page 1 of 1

Error when subclassing PlayerEntity and adding new attributes

Posted: Tue Oct 27, 2015 3:38 pm
by Mahi
My EasyPlayer causes an error when trying to use it:

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\events\listener.py', line
 92, in fire_game_event
    callback(game_event)
  File '..\addons\source-python\plugins\test\test.py', line 12, in on_player_spawn

    player = EasyPlayer.from_userid(event.get_int('userid'))
  File '..\addons\source-python\packages\custom\easyplayer.py', line 247, in fro
m_userid
    return cls(index_from_userid(userid))
  File '..\addons\source-python\packages\custom\easyplayer.py', line 207, in __c
all__
    instances[index] = super().__call__(index, *args, **kwargs)
  File '..\addons\source-python\packages\custom\easyplayer.py', line 239, in __i
nit__
    self._effects = defaultdict(list)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line
 111, in __setattr__
    for server_class in self.server_classes:
  File '..\addons\source-python\packages\source-python\entities\entity.py', line
 223, in server_classes
    for server_class in server_classes.get_entity_server_classes(self):
  File '..\addons\source-python\packages\source-python\entities\classes.py', lin
e 128, in get_entity_server_classes
    if entity.classname in self._entity_server_classes:

Boost.Python.ArgumentError: Python argument types in
    None.None(EasyPlayer)
did not match C++ signature:
    None(class IServerUnknown *)
I went through the trace all the way to this part: https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/entities/classes.py#L127-L131
But I have very little idea what it does and why it raises the error, any ideas? It used to work before an SP update, not sure which.

The error is raised whenever I try to add an attribute to the instance in the __init__ method:

Syntax: Select all

def __init__(self, index):
self._effects = defaultdict(list)
I am also using a metaclass which overrides the default __call__ method, but does call it in the overridden method, so I can't see how that would create an issue.

Posted: Tue Oct 27, 2015 3:42 pm
by satoon101
You need to call the super class' __init__ prior to setting a new attribute.

Posted: Tue Oct 27, 2015 3:46 pm
by Mahi
satoon101 wrote:You need to call the super class' __init__ prior to setting a new attribute.

I'm not calling it at all... How could I miss that, thanks!