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
Reset Scipt (Read 330 times)
Reset Scipt
Mar 19th, 2008, 2:59am
 
Hi there,

Can someone tell me how to reset a script? Or to get is to run on a schedule?

Thank your for your help in advance...

Rob
Re: Reset Scipt
Reply #1 - Mar 19th, 2008, 11:14am
 
It depends on what's gone on in the program beforehand. Basically, you'll have to write it yourself to make a script that will change everything back to how it was when the program ran for the first time.
Re: Reset Scipt
Reply #2 - Mar 19th, 2008, 9:57pm
 
Hi Manic,

Thanks for your reply. I'm still a bit lost. I'd like to start  and stop a sketch at 8am and 5pm. I - as you can tell - am completely new to Processing. Is it in the void setup I'd do that?

Thanks,

Rob
Re: Reset Scipt
Reply #3 - Mar 19th, 2008, 10:58pm
 
well, you could just put whatever code you want to run inside an if statement like this;

Quote:
if(hour()>8 && hour()<17){
 //commands go here
}
Re: Reset Scipt
Reply #4 - Mar 19th, 2008, 11:55pm
 
But that won't reset the settings.

I'm guessing you want/need to run this program in a public place.

I would recommend creating an object called Exibition or whatever, so every time you want to reset the program, you just create a new "Exibition" object with the original parameters.

Example

Code:

class Exibition{
float value;

Exibition(float value){
this.value=value;
}

void drawExibition(){
//your code here
println(value);
value++;
}
}


and

Code:

Exibition exibition1;

void setup(){
size(800,600);
exbition1=new Exibition(1); //original parameters here
}

void draw(){
if(hour()==8){
exibition1=new Exibition(1);
}
else if(hour()>8 && hour()<17){
exibition1.drawExibition();
}
}


This way, whenever the clock hits 8am a new "Exibition" object will be created on top of the old one, with the original parameters (in this case the value 1). If the clock is between 8am and 5pm it will execute the "drawExibition" function, which will actually work as the regular "draw()".

I believe the "hour()==8" might fail because if the frame falls in between a fraction of a second before or after it will not be executed,but I think that can be solved easily.

Thus, you will actually create a new exibition every day, rersetting things to its original state.

It might be overkill for your case, but I've found out it helps to simplify bigger code.
Re: Reset Scipt
Reply #5 - Mar 20th, 2008, 12:51am
 
An interesting way to do resetting of papplets:

Code:

import java.lang.reflect.*; //important!
class vars { //INITIAL VALUES BELOW
int seed = 3;
float[] weird = new float[]{3.0f, HALF_PI, 452.f};
}
int seed; //will be initialized with above values
float[] weird;

void setup(){
size(640,480);
recreate(); //True setup
}
void recreate(){
//Ignore this code if you don't understand
//(it's complex, but does cool stuff!)
Class thisclass = getClass();
Class[] inner = thisclass.getDeclaredClasses();
for(int i = 0; i < inner.length; i++){
if (inner[i].getName().equals("vars")){
thisclass = inner[i];
break;
}
}
Field[] toUpdate = thisclass.getFields();
Field[] myUpdate = getClass().getFields();
vars copier = new vars();
for(int i = 0; i < toUpdate.length; i++){
for(int k = 0; k < myUpdate.length; k++){
if(myUpdate[k].getName().equals(toUpdate[i].getName()){
myUpdate[k].set(toUpdate[i].get(vars));
break;
}
}
}
}

int lastChangeOnAM = false;
void draw(){
if (lastChangeOnAM){
if (hours()>16){
recreate(); //Reset to values in class vars
lastChangeOnAM = !lastChangeOnAM;
}
} else {
if (hours()>8){
recreate();
lastChangeOnAM = !lastChangeOnAM;
}
}
//Code here that will reset on 8:00 and 16:00
}
Page Index Toggle Pages: 1