How to add a string of text to a String array on buttonClick?

edited October 2016 in Questions about Code

So basically i want my sketch to remember what the last ten buttons are that have been clicked. I will see later on if i can make it so that it only prints the last 10 items added to the array but first i need to know how to add a string of text to a String array on buttonClick.

If i run the following sketch and press ENTER i get null in the console.

String[] buttons; 
String displayButtons;

void setup(){  
  buttons = new String[3]; 
  displayButtons = join(buttons, " : ");

void draw(){

void keyPressed() {
  if ((key=='1')) { 
   buttons[0] = "You pressed button one";

  if ((key=='2')) { 
    buttons[1] = "You pressed button two";

  if ((key==ENTER)) { 


  • edited October 2016 Answer ✓

    You are already storing the strings in the right way, the problem is only that you print a string that you created in setup() instead of printing the contents of your button-array. Try this:

      if ((key==ENTER)) { 
  • edited October 2016

    @benja thanks for your answer, after some research it got me on my way :)

Sign In or Register to comment.