Access string created in setup in draw

edited October 2014 in How To...

Hello, I have created a string setup and I am trying to use that string in draw however I cant work out how to do this. Reason being, the string is created from a table.

Here is the code:

Table table;

int place;

String myString;

void setup() {

  

  table = loadTable("speadsheet.csv", "header");

println("___________________________________");

  //println(table.getRowCount() + " total rows in table"); 

  //println(table.getColumnCount() + " total columns in table");

   for (TableRow row : table.rows()) {

    

    int number = row.getInt("number");

    

    String string1 = row.getString("column1");

    String string2 = row.getString("column2");

    String string3 = row.getString("column3");

    

String myString = ("Item " + number + " " + string1 + "," + string2 + "," + string3);

println(myString); 

  }

  

  

  size(400,400);

  background(#FFFFFF);

}

void draw(){

}

Answers

  • Answer ✓

    You've got 3 "global" variables declared at the top: table, place & myString.
    However, you end up overshadowing myString, by re-declaring it as a local variable inside the loop! [-X

  • _vk_vk
    Answer ✓

    in other words

    do

    myString = ("Item " + number + " " + string1 + "," + string2 + "," + string3);
    

    instead of

    String myString = ("Item " + number + " " + string1 + "," + string2 + "," + string3);
    
  • _vk_vk
    edited October 2014

    My answer isn't complete without GoToLoop's one. Actually I have just exemplified his… I believe you should mark his as accepted also. ;)

Sign In or Register to comment.