pygame - Python: None type object is not callable -
i'm doing game in pygame , i'm trying do, make entity target another. when call target function, "typeerror: nonetype object not callable" understood after doing research on error, occurs, when try use return value of function hasn't any. but, function isn't supposed return , don't use return value, i'm bit out of ideas. hope can me, here code: target function
def target(self,x,y): target = self.world.getpointentity(x,y) if target != none , target.get_itarget(): self.set_target(target)
call target function
self.player.target(x,y)
if have questions, feel free ask.
edit: code of getpointentity function:
def getpointentity(self, x, y, searchrange=24): entity in self.entities.itervalues(): if entity != none: distance = entity.get_distance(x, y) if distance < searchrange: return entity return none
as get_itarget function, returns true or false depending on respective entity being legal target or not. traceback points line self.player.target() full traceback:
__main2.py", line 971, in <module> game(1920,1080) __main2.py", line 795, in __init__ self.run() __main2.py", line 910, in run self.player.target(x,y) typeerror: 'nonetype' object not callable
edit: method target belongs super class of player class.
class player(livingentity): def __init__(self, name, world, image, x, y, speedmodifier, sizeradius, inv_image, filler, shadow, scx, scy, animseq, animn): livingentity.__init__(self, name, world, image, x, y, speedmodifier, sizeradius, animseq, animn) self.inventory = none self.scx = scx self.scy = scy self.addinventory(inv_image, filler, shadow) class livingentity(gameentity): def __init__(self, name, world, images, x, y, speedmodifier, sizeradius, animseq, animn, xshift=48, yshift=48): gameentity.__init__(self, name, world, images, x, y, speedmodifier, sizeradius, animseq, animn, xshift, yshift) self.target = none def set_target(self, target): self.target = target def target(self,x,y): target = self.world.getpointentity(x,y) if target != none , target.get_itarget(): self.set_target(target)
i kind of solved problem putting check target entity outside of target function. can't see differnce seems work.
inside livingentity
class have method called target
, , syntax used code within livingentity
class refer livingentity.target
method self.target
. inside livingentity.set_target
method overwrite self.target
self.target = target
assignment.
after assignment, next time call target
method python tries make call using whatever set_target
has set self.target
to, instead of calling livingentity.target
method expect use.
so got error message because told set_target
set self.target
none
.
Comments
Post a Comment