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 & HelpPrograms › trying to input text
Page Index Toggle Pages: 1
trying to input text (Read 1318 times)
trying to input text
Nov 17th, 2009, 9:56pm
 
I haven't coded in many years, and I'm developing a program to take input from a user and then encode it in color.  But I'm stuck at the beginning... and I'm wondering if I should use a different language (maybe vb or at worst c?). Processing is definitely different to think about than I'm used to.

I want to prompt the user to type a secret, then get the string they enter (ended by a newline) and save it as an array of chars.


why doesn't this work to get a string from a user?

char[] inputtext ;
int timeskeypressed =0;


void keyPressed(){
  inputtext[timeskeypressed] = key;
 println (inputtext[timeskeypressed++]);
}
void draw() {

}
Re: trying to input text
Reply #1 - Nov 18th, 2009, 4:31am
 
Quote:
why doesn't this work to get a string from a user?

Probably because you haven't initialized the inputtext array.
And of course, you will have to convert the array of chars to a String, but that's easy.
Re: trying to input text
Reply #2 - Nov 18th, 2009, 5:03am
 
Quote:
String input = "";

void keyPressed(){
  if( ((key>='A')&&(key<='Z')) || ((key>='a')&&(key<='z')) || ((key>='0')&&(key<='9')) ){
    input+= key;
    println( input );
  }
  if( (key==ENTER) || (key==RETURN) ) {
    println( "The user has entered the secret: '" + input + "'" );
    if (input.equals( "Passw0rd" )) {
      println( "That is the correct secret!!!" );
    } else {
      println( "That is not correct." );
    }
    input = "";
  }
}

void draw(){
}



Hope this helps.
Page Index Toggle Pages: 1