We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
My sketch gives me a .csv output file. I want to run my sketch multiple times within a loop (in every iteration I'm changing some parameters so that I will have different outputs) to get the output files for each run (I'm saving them with a different name at each time), but it always stops after the first time.
So how can I get my code to run more than once?
Answers
If you use
saveTable()
inside a for loop and make sure you assigned a different name, that should work. Share your code, so people could help you to find out what the problem is.when you program in active mode (and not in static mode) draw() runs on and on
unless you use noLoop somewhere
see
Static sketches and Interactive sketches
http://portalsfordeveloping.wikia.com/wiki/Functions#Static_sketches_and_Interactive_sketches
;-)
Thanks for the replies. I think the code is really too long to share here. But I'm using Processing via Eclipse and I defined a main class in Eclipse that calls my main class in Processing. Here is the main method from my main class that I'm using to call Processing's main class, which is named as the Perry class:
static public void main(String[] passedArgs) {
I actually need two output files from each run, a text file and a .3dm (Rhinoceros) file. I can get all these successfully for the first iteration but then it just stops.
It's not really a small sketch actually. The code has more than 1200 lines in 9 classes. That's the reason I switched to Eclipse from Processing IDE in the first place.
In my code everything happens within the setup() method, I don't even have a draw() method. But it works just fine for the first time as I said on my previous post.
I think all I need to do is to kill the process going on right after I get the desired outputs and right before the second iteration starts. So that the second iteration can start just as the first one. But I couldn't figure out how to do that.
Looking at your re-posted question here:
http://forum.processing.org/two/discussion/9815/processing-at-eclipse-run-a-sketch-more-than-once
I can foresee lotsa problems...
new
Thread called "Animation" is instantiated.Thank you for your replies GoToLoop. I instantiated PApplet inside the for loop because I want to get number of outputs that is the same with number of iterations. And for each iteration I need to run my code from scratch. So I think I should kill the newly instantiated "Animation" thread at the end of each iteration, so that it can be launched again at the next iteration. Does that sound right? And how can I kill the Animation thread?
I did place the loop in the draw() method and it worked just fine :) thanks. The only problem I have right know is I can't get rid of the drawings from the previous iterations. I tried the background(int) function but had no luck. Do you have any idea how I can solve this problem?
Thank you again, I really appreciate the help.
I followed your advise and everything looks great except one thing. I get one .3dm file output from each run of the iteration, actually this is the purpose of my code, but I can't get rid of the drawings from the previous iterations. So my final .3dm output file from the last iteration contains every drawing from the very first iteration to the very end. I have to find a way to prevent this. In the end I should have the output files with only the drawings from their own iteration.
This means I have to find a way to clear everything in the end of an iteration before the next iteration of draw() method starts. The only function in the documents I found so far is to call background(int) function but it only changes the background and doesn't clear anything.
Well I solved that problem as well. I'm using a library (iGeo Computational Design Library) and have to call a function from there to clear the screen before each iteration. So it's all figured out. And again thank you for all your help.