We are about to switch to a new forum software. Until then we have removed the registration on this forum.
For example, is there a way to update the key variable during a loop that is within the draw function so the following would work?
Thanks in advance.
David
boolean done = false;
int count = 0;
void setup(){
}
void draw(){
while(!done){
count += 1;
if(key == 'a') done = true;
}
println(count);
exit();
}
Answers
I don't believe Processing's framework updates system variables key or keyCode during draw()! [-X
However, Processing got a parallel Thread which enqueues every input event transpired.
We just need to implement which 1s we're interested in!
In your case, that'd be keyPressed() in order to check for 'A' and display final frameCount: *-:)
As said, when draw() is executing, Processing variables are not updated. The common idiom with Processing is to use draw() as the body of a loop:
PS.: you should read To newcomers in this forum: read attentively these instructions too...
I realize that using draw() as the body of the loop is the common idiom with Processing. I was wondering whether it is possible to implement a more sequential way of organizing a game loop. For example, suppose a game loop had this structure:
Ask the user for input ("enter your age").
Get input from user.
process input.
ask user for more input (if age is greater than 70, ask the user to enter their favorite song, else ask user to enter their favorite tv show.)
get input from user.
process input (recommend a movie).
Could you implement this structure in Processing, or would you have to translate it into one using states or something equivalent?
The best way to achieve this kind of structure - in nearly any programming language - in fact is a state system, at least in my opinion. Statesystems can be class or switch/if based and are relatively easy to implement in Processing. A quick example how to implement a simple switch based statesystem:
Wow! Nice keyboard input, @Poerch ! I've got a not-too-nice using JOptionPane though: 8-|
I agree: Wow! Both are really useful examples. Thanks to you both.
David
@GoToLoop, @dlewine: Haha, thanks! :D I like these oldschool-ish console inputs.
Oh, there's another 1 w/ typing text boxes: <):)
http://studio.processingtogether.com/sp/pad/export/ro.9Zo$UbIWYZEDR/latest