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 & HelpSyntax Questions › possible to get input during setup
Page Index Toggle Pages: 1
possible to get input during setup? (Read 963 times)
possible to get input during setup?
Feb 28th, 2010, 1:31pm
 
My son wrote a program that can run in either of two modes. He would like to allow the user to select one of these two modes by pressing a key during the setup. But, it seems as though `keypressed` does not get invoked until after setup has been called. Is there any way to get user input while setup is running?
Re: possible to get input during setup?
Reply #1 - Feb 28th, 2010, 2:29pm
 
thats not the way i would do it.
if you have different modes, create an int variable, where 0 is undefinied and 1-x are your different modes.
So when starting the programm you are in mode = 0.
i dont know how the programm works, but maybe you use a switch or "ifs" to execute the different modes.
so the first mode 0 would print a screen saying something like "please select mode, press key 1 or 2"
by pressing the keys you change the int variable. and the next mode you definied in your switch would be called.

hope that makes sense somehow, if not, i will make an example.
Re: possible to get input during setup?
Reply #2 - Feb 28th, 2010, 4:27pm
 
Quote:
int mode = 0;
void draw(){
  switch( mode ){
    default:
    case 0:
      background(0);
      break;
    case 1:
      background(128,0,0);
      break;
    case 2:
      background(0,0,128);
      break;
  }
}
void keyPressed(){
  if( key == '1' && mode == 0){ mode = 1; }
  if( key == '2' && mode == 0){ mode = 2; }
}



I made an example anyway.  Grin
Re: possible to get input during setup?
Reply #3 - Mar 1st, 2010, 12:51am
 
thx Smiley btw you can just drop the two brackets.
if there is just one line after an "if" you dont need them
if( key == '1' && mode == 0)mode = 1;
Re: possible to get input during setup?
Reply #4 - Mar 1st, 2010, 3:27am
 
I know. But  not using them always bothers me. Personal choice.
Page Index Toggle Pages: 1