[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pygame] Does my sprite need a __len__ method? (Corrected message)
I'm getting an error message that I can't seem to correct. I was hoping someone
could give me a clue.
ERROR MESSAGE: Platform instance has no attribute '__len__'
Platform is a sprite class I created.
I call this:
for sprite in self.elves.sprites():
# tell AI to update each elf based on current players and barriers
self.AI.update(sprite, self.playerGroup.sprites(), self.barriers.sprites())
Here's the AI.update function. If I don't call this function, I don't get the
error message.
def update(self, controlledSprite, playerList, barrierList):
if not controlledSprite.patrol:
# create the biggest rect possible centered on the current
# position and make this the patrol rect. the elf will circle
# about the patrol rect until it has reason to attack or flee
controlledSprite.patrol = Rect(controlledSprite.rect)
pr = controlledSprite.patrol
# grow left
while pr.collidelist(barrierList) == -1:
if pr.left < SCREENRECT.left: break
pr.move_ip(-1,0)
pr.inflate_ip(1,0)
pr.move_ip(1,0)
pr.inflate_ip(-1,0)
# grow right
while pr.collidelist(barrierList) == -1:
if pr.right > SCREENRECT.right: break
pr.inflate_ip(1,0)
pr.inflate_ip(-1,0)
# grow up
while pr.collidelist(barrierList) == -1:
if pr.top < SCREENRECT.top: break
pr.move_ip(0,-1)
pr.inflate_ip(0,1)
pr.move_ip(0,1)
pr.inflate_ip(0,-1)
# grow down
while pr.collidelist(barrierList) == -1:
if pr.bottom > SCREENRECT.bottom: break
pr.inflate_ip(0,1)
pr.inflate_ip(0,-1)
Here's some error data I've printed:
Error trying to update: Elf: 0 rect: <rect(1026, 680, 32, 43)> vx: 0 vy: 0 x:
10
42.0 y: 701.0 acc: 0 lives: 3
patrolRect: <rect(0, 657, 1200, 75)>
barriers: [<Platform sprite(in 2 groups)>, <Platform sprite(in 2 groups)>,
<Plat
form sprite(in 2 groups)>, <Platform sprite(in 2 groups)>, <Platform sprite(in
2
groups)>, <Platform sprite(in 2 groups)>]
<Platform sprite(in 2 groups)> <rect(241, 637, 310, 20)>
<Platform sprite(in 2 groups)> <rect(585, 101, 20, 530)>
<Platform sprite(in 2 groups)> <rect(68, 340, 260, 20)>
<Platform sprite(in 2 groups)> <rect(822, 277, 290, 20)>
<Platform sprite(in 2 groups)> <rect(720, 732, 480, 20)>
<Platform sprite(in 2 groups)> <rect(0, 790, 1200, 20)>
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com