Loading...
Logo
Processing Forum
Hey all, 

Im trying to have the user type in their player name and then they hit enter and it loads the array to a string but for some reason it's not working I really can't work it out im sure it's staring me in the face but i just can't crack it, please help :) 



Copy code
  1. int j;
  2. void setup()
  3. {
  4.   
  5.   size(500,500);
  6.   
  7. }

  8. void draw()
  9. {
  10.   
  11. }

  12. void keyTyped() {
  13.  char[]  name = new char[20];  
  14.  name[j] = key;  

  15.  
  16.  if (keyPressed)
  17.  {
  18.    if( key == 'ENTER')
  19.    {
  20.      String player_name = new String(name);
  21.      
  22.      println(player_name);
  23.    }
  24.    
  25.  }
  26.   j += 1;
  27. }

Replies(2)

this would be an easy way to do it...

Copy code
  1. String player_name = "";
    void setup()
    {
     
      size(500,500);
     
    }

    void draw()
    {
     
    }

    void keyTyped() {

     
        if (key == ENTER) {

          println(player_name);
       }
       player_name +=key;
     
    }