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 › FIRST TIME THRU SWITCH
Page Index Toggle Pages: 1
FIRST TIME THRU SWITCH (Read 295 times)
FIRST TIME THRU SWITCH
Dec 22nd, 2008, 6:54pm
 
How would one go about coding this outside of reading in a file with a switch on it, which is updated and then written back out to the file.
Re: FIRST TIME THRU SWITCH
Reply #1 - Dec 22nd, 2008, 8:35pm
 
Is this it?:
Code:


String lines[] = loadStrings("switchlist.txt");
println("there are " + lines.length + " lines");
for (int i=0; i < lines.length; i++) {
 println(lines[i]);
 if(lines[i].equals("OFF")){
   lines[i] = "ON";
 }else if(lines[i].equals("ON")){
   lines[i] = "OFF";
 }
}

// now write the strings to a file, each on a separate line
saveStrings("data/switchlist.txt", lines);




content of switchlist (load it into data folder)
Code:

ON
OFF
ON
OFF
OFF


Run this several times - the switches in the file will toggle.
Re: FIRST TIME THRU SWITCH
Reply #2 - Dec 22nd, 2008, 11:58pm
 
What I was wondering was if there was a slicker way of coding the solution.
In my program I am having a pseudo conversation with the user.
So obviously, immediately after the program gets executed the the first thing it does is send out a WINDOW and then waits for mouse or keyboard response. When the program gets executed again it checks for that response and acts accordingly.
But its that very first time I am trying to detect with a view to displaying a window with differing contents to that of the window displayed on the nth time thru.
Re: FIRST TIME THRU SWITCH
Reply #3 - Dec 23rd, 2008, 12:10am
 
Yes, there are a lot better ways of expressing it, but is there a problem with the solution provided, other than its total lack of elegance? Smiley You did want the program to use a file, rather than IPC, right?

Maybe a working mock project code would help clarify the problem at hand.
Page Index Toggle Pages: 1