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 › Beginner: Checking if a variable is declared
Page Index Toggle Pages: 1
Beginner: Checking if a variable is declared (Read 495 times)
Beginner: Checking if a variable is declared
Mar 11th, 2007, 9:29pm
 
Hi,
I'm trying to move from ActionScript to processing and am trying to figure out a simple little problem.

I have 2 arrays, one that has values that update each frame (vals) and one that holds onto the last set of those values (lastVals). But on the first run through how can I make it so that the lastVals sees that vals has not been created yet and set itself to 0?

or possibly another way of approaching this... how can I make variables declared in setup() usable in draw()?

thanks
Re: Beginner: Checking if a variable is declared
Reply #1 - Mar 11th, 2007, 9:37pm
 
Code:
 int[] vals;
int[] lastVals;

void setup()
{
//if you initialise vals here, lastvals will update at the start of draw just fine.
//IF for some reason you don't want to set them up just yet, then
// the test below will check to see if vals has been filled.
}

void draw()
{
if(vals!=null)
{
arraycopy(vals,lastVals);
}
//set up this frames vals next.
vals=new int[10]; //actually it's better to do this in setup
// than creating a new array each frame.
}
Re: Beginner: Checking if a variable is declared
Reply #2 - Mar 11th, 2007, 10:17pm
 
thank you!

that solved my problem.
Page Index Toggle Pages: 1