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 › Save settings when closing
Page Index Toggle Pages: 1
Save settings when closing (Read 870 times)
Save settings when closing
Nov 2nd, 2009, 2:53am
 
I have a lot sliders. I wont to save the slider position when I close the application. I'm trying stop() and destroy() but it seems that both don't will be called.
Re: Save settings when closing
Reply #1 - Nov 2nd, 2009, 3:33am
 
i once had a similar need, i just wrote them when closing into a txt file and read them at start. but this is a feature i am really looking for in controlP5 for example.
Re: Save settings when closing
Reply #2 - Nov 2nd, 2009, 3:40am
 
But how you made it? How to I know when the window is closing?
Re: Save settings when closing
Reply #3 - Nov 2nd, 2009, 4:05am
 
its stop.... like in this example...

Code:
int[] x = new int[0];
int[] y = new int[0];

void setup()
{
 size(200, 200);
}

void draw()
{
 background(204);
 stroke(0);
 noFill();
 beginShape();
 for (int i = 0; i < x.length; i++) {
   vertex(x[i], y[i]);
 }
 endShape();
 // Show the next segment to be added
 if (x.length >= 1) {
   stroke(255);
   line(mouseX, mouseY, x[x.length-1], y[x.length-1]);
 }
}

void mousePressed() { // Click to add a line segment
 x = append(x, mouseX);
 y = append(y, mouseY);
}

void stop() { // save when closing window
 String[] lines = new String[x.length];
 for (int i = 0; i < x.length; i++) {
   lines[i] = x[i] + "\t" + y[i];
 }
 saveStrings("lines.txt", lines);

}
Re: Save settings when closing
Reply #4 - Nov 2nd, 2009, 7:10am
 
Mhmm, it seems not to work in eclipse. Here is my function:

Code:

public void stop() {
String words = "apple bear cat dog";
String[] list = split(words, ' ');

// now write the strings to a file, each on a separate line
saveStrings("nouns.txt", list);
}


Re: Save settings when closing
Reply #5 - Nov 2nd, 2009, 7:19am
 
i tested your little sketch. I had to add draw() to prevent it from writing the file imidiatly before closing but if i run this :

Code:
 void draw(){
 }

 void stop() {
String words = "apple bear cat dog";
String[] list = split(words, ' ');

// now write the strings to a file, each on a separate line
saveStrings("nouns.txt", list);
}



everything works the way it should. Writing the file when closing the sketch.
Re: Save settings when closing
Reply #6 - Nov 2nd, 2009, 9:16am
 
Maybe it's an eclipse quirk.
Page Index Toggle Pages: 1