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 › param () and global variables
Page Index Toggle Pages: 1
param () and global variables (Read 449 times)
param () and global variables
May 23rd, 2006, 4:16pm
 
Hello,

(this is while programming in continuous mode)

I have an Array, needed as a global variable, thus declared before setup() and draw(). Its size is recieved from a website, thanks to param (). When calling param() outside setup() and draw(), it doesn't work (unexpected token void, pointing at the setup () ).

How can we manage that ?
Re: param () and global variables
Reply #1 - May 23rd, 2006, 4:27pm
 
declare outside of any classes / methods, then initialize inside:
Code:

int[] wh;
void setup()
{
int _w = Integer.parseInt(param("myWidth"));
int _h = Integer.parseInt(param("myHeight"));
wh = new int[]{ _w, _h };
// ...
}

F
Re: param () and global variables
Reply #2 - May 23rd, 2006, 4:42pm
 
i should add:

the initialization of varibles or objects in "global" (PApplet) scope may happen at any time. so before you use them you have to either make sure they have been initialized or initialize them at that point. good practice would be to use setup() for that, since that's what it is meant for ...

F
Re: param () and global variables
Reply #3 - May 23rd, 2006, 4:58pm
 
OK thanks, it works fine Smiley

You're right concerning the methodology, it seems much cleaner like this; but I don't know why, I was convinced I had to set the size of the array when declaring it.
Page Index Toggle Pages: 1