By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,474 Members | 3,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,474 IT Pros & Developers. It's quick & easy.

pygame.key.get_pressed[K_a], K_a is not defined!?

P: n/a
if pygame.key.get_pressed[K_a]:
print "Muppet"

K_a is not defined.
but yes it is. why do i get this error?

this works:
if pygame.key.get_pressed():
print "donkey"
Jun 27 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
globalrev schrieb:
if pygame.key.get_pressed[K_a]:
print "Muppet"

K_a is not defined.
but yes it is. why do i get this error?
No it isn't - otherwise you wouldn't get this error, wouldn't you?

What IS defined is

pygame.K_a

Or if you do

from pygame import K_a

then K_a is defined as well.

Diez
Jun 27 '08 #2

P: n/a
On 2 Maj, 18:13, "Diez B. Roggisch" <de...@nospam.web.dewrote:
globalrev schrieb:
if pygame.key.get_pressed[K_a]:
print "Muppet"
K_a is not defined.
but yes it is. why do i get this error?

No it isn't - otherwise you wouldn't get this error, wouldn't you?

What IS defined is

pygame.K_a

Or if you do

from pygame import K_a

then K_a is defined as well.

Diez
ok thanks
if (key.get_pressed[K_t] and key.get_pressed[K_f]):
print "Yup!"

said int he tut it confused me.
anyway i changed it and the list or dict from keygetpressed is all
zeros but the K_a always is true whether i push it or not.


Jun 27 '08 #3

P: n/a
print pygame.K_a displays 97 btw. what does that mean? i though it
would return true or false or 0 or 1.
Jun 27 '08 #4

P: n/a
On May 2, 12:03 pm, globalrev <skanem...@yahoo.sewrote:
print pygame.K_a displays 97 btw. what does that mean? i though it
would return true or false or 0 or 1.
That's probably the key code value. Or the ASCII representation for
the key. You'd have to read the pygame docs to really know.

Mike
Jun 27 '08 #5

P: n/a
globalrev schrieb:
On 2 Maj, 18:13, "Diez B. Roggisch" <de...@nospam.web.dewrote:
>globalrev schrieb:
>>if pygame.key.get_pressed[K_a]:
print "Muppet"
K_a is not defined.
but yes it is. why do i get this error?
No it isn't - otherwise you wouldn't get this error, wouldn't you?

What IS defined is

pygame.K_a

Or if you do

from pygame import K_a

then K_a is defined as well.

Diez

ok thanks
if (key.get_pressed[K_t] and key.get_pressed[K_f]):
print "Yup!"

said int he tut it confused me.
anyway i changed it and the list or dict from keygetpressed is all
zeros but the K_a always is true whether i push it or not.
most probably because

key.get_pressed[K_t]

is bogus. It's a method you need to call that returns a list of bools
that are True for a given index if the key is pressed. Which the 97 is -
an index to that.
Did you actually bother to read the docs?

http://www.pygame.org/docs/ref/key.h...ey.get_pressed

Diez
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.