This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Why does an error happen when I try to call the subclass of "SpriteNode"?
happy_variable last edited by
Here is the subclass of SpriteNode
def init(name, duration, from_brick):
self.name = name
self.duration = duration
self.from_brick = from_brick
def __setattr__(name, duration, from_brick): SpriteNode.__setattr__(name, duration, from_brick)
It actually must display a Powerup on the screen.
Don't worry about the from_brick.position attribute in the init function, the from_brick attribute of my class must be a SpriteNode.
Notice: I have done all the indents, but they may be not displayed, don't worry.
Here is how I call the class to create a Powerup:
pup = Powerup("plf:Item_Star", 30, brickOnScreen)
The brickOnScreen variable was defined.
Gives a TypeError, that init() takes 3 arguments, but 4 were given (The error bookmark points at the line where I assign the class to the pup variable.
Thanks for your answers, programmers!
bennr01 last edited by bennr01
@happy_variable try the following instead of
__init__ (self, name, dration, from_brick):
In python, class methods (except the staticmethods or classmethods) are called with the instance of the class as the first argument.
EDIT: You will also need to replace
SpriteNode.__setattr__(name, duration, from_brick)with
SpriteNode.__setattr__(self, name, duration, from_brick).
This is because
SpriteNode.__setattr__is a unbound class method.