Error when subclassing PlayerEntity and adding new attributes

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Error when subclassing PlayerEntity and adding new attributes

Postby Mahi » Tue Oct 27, 2015 3:38 pm

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Oct 27, 2015 3:42 pm

You need to call the super class' __init__ prior to setting a new attribute.
Image
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Tue Oct 27, 2015 3:46 pm

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!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 143 guests