[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Why Won't My Pizza Fall?



Greetings,
I have the same source code on my computer, and get the following error when
I run it:

Traceback (most recent call last):
  File "falling_pizza.py", line 25, in ?
    image = pizza_image, dx = 0, dy =1)
  File "falling_pizza.py", line 14, in __init__
    self.init_sprite(screen = screen, x = x, y = y,
AttributeError: 'Pizza' object has no attribute 'init_sprite'
Exception exceptions.NameError: "global name 'screen' is not defined"
in <bound method Pizza.__del__ of <__main__.Pizza object at
0xb7e41b6c>> ignored

This book has a customized version of livewires, which I've installed properly.
(All the other code works as advertised, including the Asteroids game in Ch12.)
I've used dir() to look for the offending init_sprite, and indeed, it
doesn't exist.
Of course, I'm not absolutely sure I've looked in the right place? If you were
looking for it, what would your 'print dir()' look like?
The final program (pizza_panic.py) in this chapter works fine.
No other program uses self.init_sprite().
-- 
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/python/index.html

On Jan 12, 2008 7:21 PM, earlylight publishing
<earlylightpublishing@xxxxxxxxx> wrote:
> Hey There Everyone,
>
> I'm following an example in a book and I can't find the error that's
> preventing this program from running.  It's just an example of how to get a
> sprite moving.  The images are all in the right folder.  I can run the
> program and get a stationary sprite to appear.  The trouble seems to come up
> when I add "dx" and "dy"  Here's the code.
>
>
> from livewires import games
>
> SCREEN_WIDTH = 640
> SCREEN_HEIGHT = 480
>
> class Pizza(games.Sprite):
>     """A falling pizza."""
>     def __init__(self, screen, x, y, image, dx, dy):
>         """Initialize pizza object."""
>         self.init_sprite(screen = screen, x = x, y = y, image = image,
>                              dx = dx, dy = dy)
>
> #main
> my_screen = games.Screen(SCREEN_WIDTH, SCREEN_HEIGHT)
> wall_image = games.load_image("skywall.png", transparent = False)
> my_screen.set_background(wall_image)
> pizza_image = games.load_image("pizza.png")
> Pizza(screen = my_screen, x = SCREEN_WIDTH/2, y = SCREEN_HEIGHT/2,
>           image = pizza_image, dx = 0, dy = 1)
>
> my_screen.mainloop()
>
> ___________
>
>
> Here's the error message:
>
>
> Traceback (most recent call last):
>   File "C:/Python25/Chapter 11/movingsprite.py", line 25, in <module>
>     image = pizza_image, dx = 0, dy =1)
>   File "C:/Python25/Chapter 11/movingsprite.py", line 15, in __init__
>     dx = dx, dy = dy)
> TypeError: init_sprite() got an unexpected keyword argument 'dx'
>
>
> Thanks in advance for any help you can give me.  :-)
>  ________________________________