We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpProcessing Implementations › problem with key_pressed == SPACE
Page Index Toggle Pages: 1
problem with key_pressed == SPACE (Read 1808 times)
problem with key_pressed == SPACE
Feb 11th, 2010, 9:02pm
 
I get an error when trying to detect SPACE in ruby-processing.
I get this: Code:
Exception in thread "Animation Thread" /home/brian/.gem/ruby/1.8/gems/ruby-processing-1.0.8/lib/ruby-processing/app.rb:250:in `const_missing': uninitialized constant Snake::SPACE (NameError)


While the other keys such as ENTER work fine.
Why is this happening?

All help appreciated.
Re: problem with key_pressed == SPACE
Reply #1 - Feb 12th, 2010, 8:15am
 
The SPACE constant doesn't exist because space isn't a special character. You can simply do this:

Code:
if key == ' ' 



All of the constants for non-ASCII keys are listed here:

http://processing.org/reference/key.html

Hope that helps. Here's a test sketch that draws an ellipse when you press the space bar:

Code:
def draw
background 200
if key_pressed? && key == ' '
oval 10, 10, 100, 100
end
end

Re: problem with key_pressed == SPACE
Reply #2 - Feb 14th, 2010, 1:45pm
 
thanks!
Page Index Toggle Pages: 1