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 › Setup runs more than once
Page Index Toggle Pages: 1
Setup runs more than once (Read 297 times)
Setup runs more than once
Jul 25th, 2008, 4:31pm
 
Hi

Setup is called more than once if (for instance) I set the size. i.e -

void setup () {
 
println("ping!");

size(500, 500);

}

void draw () {
 
 
}

- results in two pings. Without the size setting, there's just one. This can be a problem e.g. if initialising sounds - I get them twice.

I've dealt with it by a boolean and my own 'setup' with the draw method, but shouldn't setup only run once? What's a-goin on? Not sure if this is bug or just something I'm missing....?
Re: Setup runs more than once
Reply #1 - Jul 25th, 2008, 6:12pm
 
In size() reference page, I read: "The size() function must be the first line in setup()."
This is not enforced, and you can safely ignore this rule in some cases, ie. it can work as expected (eg. if I add just smooth() and noLoop() before size(), it is still run only once) but be prepared to some side effects (even if this one is quite surprising!).

In other words, I can reproduce the issue in v.0141, and if I move size() before println(), it prints only once.
Re: Setup runs more than once
Reply #2 - Jul 27th, 2008, 9:29pm
 
Dan_Olner wrote on Jul 25th, 2008, 4:31pm:
results in two pings. Without the size setting, there's just one. This can be a problem e.g. if initialising sounds - I get them twice.

I've dealt with it by a boolean and my own 'setup' with the draw method, but shouldn't setup only run once What's a-goin on Not sure if this is bug or just something I'm missing....

from http://processing.org/reference/size_.html
Again, the size() method must be the first line of the code (or first item inside setup). Any code that appears before the size() command may run more than once, which can lead to confusing results.
Page Index Toggle Pages: 1