473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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
5 4184
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Askari | last post by:
(Help for Pygame module) Hi, How I can make a "fadeout text"(alpha at 255,254,253...0) on a surface and my surface's background must be transparatly? Note : I can do a fadeout but with a...
0
by: Terry Hancock | last post by:
I've been trying to use "happydoc" to document a source tree that I'm working on. It does pretty much what I want, except: Version 2.1: Creates a weird directory structure for the HTML pages...
22
by: Tony Houghton | last post by:
I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use "~/.bombz", in Windows something like "C:\Documents...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
4
by: Mizipzor | last post by:
I have some troubles with a member variable that seems to be missing in a class. In short, heres what I do; class A is the parent class, B inherits from A and C inherits from B (hope I used the...
14
by: Alberto Vieira Ferreira Monteiro | last post by:
Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Alberto Monteiro
14
raubana
by: raubana | last post by:
I made a simple 3d engine with python, but it's slow, intersections don't show, and faces dissapear when your at a certian place. Here's the link: http://www.mediafire.com/?dggmjfnfts0 If you...
1
by: globalrev | last post by:
import pygame pygame.mixer.music.load(example1.mp3) pygame.mixer.music.play(loops=1, start=0.0) Traceback (most recent call last): File "C:\Python25\myPrograms\pygameProgs\musicexp.py",...
2
by: npcarp | last post by:
Is this hard? I am introducing Python to my students and want to make a simple, interactive program that will, while it's running, 'listen' for any keyboard events. That is, I don't want to...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.