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 › where and how to use loadStrings
Page Index Toggle Pages: 1
where and how to use loadStrings (Read 876 times)
where and how to use loadStrings
Jan 29th, 2007, 2:05am
 
hey someone please help. i try to load a txt file into an array. my problem is: i dont know where to do it. i dont want to do it inside the draw function, because it should only be loaded once (its huge). but if i do it outside the draw function, it doesnt work!!! thats my code:

String code[] = loadStrings("codes_test.txt");
String words[] = loadStrings("words_test.txt");

void setup(){
 size(300,400);
 stroke(255);
 noLoop();
}

void draw(){
background(0);
if (mousePressed && (mouseButton == LEFT)) {
   float X=mouseX;
   float Y=mouseY;
    arc(X, Y, 18, 25, 0, 2*PI);
   }
}

void mousePressed() {
 redraw();
}

Thats the error:
The file "codes_test.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.


of course i checked the files locations inside the data folder...

i would really appreciate some help Smiley
Re: where and how to use loadStrings
Reply #1 - Jan 29th, 2007, 4:02am
 
You should call loadStrings() in setup(), but declare your variables as global, i.e.

Code:

String code[];

void setup(){
size(300,400);
code = loadStrings("codes_test.txt");
}
Re: where and how to use loadStrings
Reply #2 - Jan 29th, 2007, 12:21pm
 
great! it works.
thanks very much.
Page Index Toggle Pages: 1