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 › Load text file and comparing contents not working
Page Index Toggle Pages: 1
Load text file and comparing contents not working (Read 843 times)
Load text file and comparing contents not working
Apr 30th, 2010, 4:20am
 
I have created a text file which I am using to determine whether a background image, or canvas colour is shown:-

Code:
void getPrefs_setbackground() {

 // Set the background
 String[] prefs;
 prefs = loadStrings("background.txt");
 // If the file exists do this
 if (prefs != null) {
   String[] pieces = split(prefs[0], ',');
     if (pieces[0] == "colour" && pieces.length == 2) {
       fill(int(pieces[1]));
       rect(0,0,width,height);
       println ("egypt");
     } else  {        
       background_pic = loadImage(pieces[0]);
       image(background_pic, 0, 0);
     }

 // If the file doesn't exist set the background to a solid colour
 } else {
     // Set the background to be a solid colour
     fill(canvasColor);
     rect(0,0,width,height);
 }
 
}


However, this portion doesn't work and I am  not sure why:-

Code:
if (pieces[0] == "colour" && pieces.length == 2) { 



The pieces[0] array does contain the string colour, so why does the IF statement not work?

background.txt looks like:-

colour,123


Please help.
Re: Load text file and comparing contents not working
Reply #1 - Apr 30th, 2010, 4:46am
 
That's, literally, a FAQ.
Read or re-read the String reference page, look at equals().
Re: Load text file and comparing contents not working
Reply #2 - Apr 30th, 2010, 5:05am
 
Thank you! Smiley
Page Index Toggle Pages: 1