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.
Page Index Toggle Pages: 1
Restart sketch (Read 1280 times)
Restart sketch
Jan 20th, 2010, 2:02pm
 
Hi everyone,

I've wondered if it's possible to really restart a sketch with a command, but not just calling up setup() .

Please tell me if you know of any, thanks Cheesy
Re: Restart sketch
Reply #1 - Jan 20th, 2010, 2:30pm
 
You can just write your sketch in such a way that it can be reset. That is, have setup() call a function that resets all the data in your sketch back to it's original values. Here's a quick example:

Quote:
int rect_x, rect_y;

void reset_sketch(){
  rect_x = 10;
  rect_y = 10;
  background(0);
}

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

void draw(){
  stroke(255);
  line(mouseX, mouseY, pmouseX, pmouseY);
  noStroke();
  fill(0,200,100);
  rect(rect_x, rect_y, 10, 10);
  fill(0,0,0,5);
  rect(0,0,width,height);
}

void mouseClicked(){
  rect_x = mouseX-5;
  rect_y = mouseY-5;
}

void keyReleased(){
 if( key == ' ' ){
  reset_sketch();
 } 
}

Re: Restart sketch
Reply #2 - Jan 21st, 2010, 8:14am
 
Thanks for your answer, but it won't help me as I don't just wanna reset my variables.

Maybe I should have written what I wanna do. I'm using SpringGUI and it has a bug which causes that once you use a function of SpringGUI keyPressed is not recognized anymore, so what I wanted is to restart the programm, so that it is like I've never used a function of SpringGUI.
Maybe you understand what my problem is.

Maybe it can't be fixed though
Re: Restart sketch
Reply #3 - Jan 21st, 2010, 8:29am
 
That sounds like a pretty fundamental bug.  I'd be tempted to look for an alternative to SpringGUI; not least given the 'please read this first' warning on the developer's site...
Re: Restart sketch
Reply #4 - Jan 21st, 2010, 9:10am
 
Yes, I love the idea of SpringGUI as it is (was?) the only GUI for Processing allowing a simple paste in a text field...
But it have been removed from the lists of libraries for Processing because it was no longer (fully) compatible with 1.0 and up.
Re: Restart sketch
Reply #5 - Jan 21st, 2010, 9:10am
 
Interfascia seems to be a good alternative, i'll take a look at it, thank you
Page Index Toggle Pages: 1