[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Immovable Car, and TypeError
On Sat, Sep 15, 2001 at 12:33:07AM -0400, MBr8473501@aol.com wrote:
> You guys helped me out with the invisible car, and now I have that settled,
> but now, in typical newbie fashion, I've messed up something else. Now, my
> car doesn't move at all, and I'm getting all types of TypeErrors, such as
> this:
>
> actor.erase(screen, background)
> TypeError: unbound method erase() must be called with instance as first
> argument
>
> I'm getting this with all kinds of code. Here's the full code, and I'll tell
> ya when we get to what I believe to be the trouble area.
Ok.. I'm gonna try to help.. but.. *attention* I just woke up :)
> ######!!!???All kinds of type areas in this section of
> code???!!!######
>
> #Clear screen and update actors
> for actor in [Player]:
> actor.erase(screen, background)
> actor.update()
>
> # Move the player
> direction = keystate[K_RIGHT] - keystate[K_LEFT]
> Player.move(direction)
>
> ######!!!???End what I believe to be THE SECTION???!!!######
Let's start with the for loop. Your looping over [Player] here. Now what
is Player? You may possibly think it is your game's player class instance but
no this is not the case. Note the difference between *player* and *Player*.
So what you're actually doing is setting actor to equal your Player class and
trying to call a method of a class which has not been instantiated (therefore
all methods are _unbound_)
Here's a small example for that:
>>> class A:
... pass
...
>>> a = A()
>>> for b in [A]:
... print b
...
__main__.A
>>> a
<__main__.A instance at 0x80d8db4>
You see the difference? b is the actual class A whereas a is an instance of
this class.
K.. I'll leave it to you to understand that and correct your code. If you
really don't manage to get it working.. just post again :).. but there's
nothing better than correcting one's own errors in order to learn.
========
Second problem.. your call of Player.move(direction). This is pretty much
similar. Again the same difference between *player* and *Player*.
Short summary: Take care of case sensitivity.
HTH
--
Raiser, Frank aka CrashChaos
IRC: 141.30.225.9:6667 #United-Programmers
"Taxation, gentlemen, is very much like dairy farming. The task is to
extract the maximum amount of milk with the minimum of moo. And I am afraid
to say that these days all I get is moo."
-- (Terry Pratchett, Jingo)
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org