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 › problems with class{} and setup()
Page Index Toggle Pages: 1
problems with class{} and setup() (Read 622 times)
problems with class{} and setup()
Dec 6th, 2005, 5:19pm
 
Sorry, but I have tried to solve this error with no luck...

class element {
int x, y;
   element(int x, int y){
   x = x;
   y = y;
   }
}

element[] obj = new element[1];
obj[0] = new element(1,1);

The above works fine, until I add...

void setup(){
 size(350, 300);
}

Error: unexpected token: void

And if I swap them around so that setup() comes before the class..

Error: expecting RBRACK, found '0'
Re: problems with class{} and setup()
Reply #1 - Dec 6th, 2005, 7:26pm
 
I think that this is what you want:

class element
{
   int x, y;
   element(int xIn, int yIn)
   {
     x = xIn;
     y = yIn;
   }
}

void setup()
{
 size(350, 300);
 element[] obj = new element[1];
 obj[0] = new element(1,1);
}

Two things to note here. By adding the setup method you're switching from Basic Mode to Continuous Mode. You want to initialize your global objects in the setup method in Continuous Mode. See this link for more information: http://processing.org/reference/environment/index.html

The second is with your constructor. The input values x and y to the element constructor are hiding the member values x and y, which means your class variables won't be initialized.
Re: problems with class{} and setup()
Reply #2 - Dec 6th, 2005, 8:45pm
 
Oh, heh.. oops Tongue

That was a very informative reply. Thank you very much, cchoge Smiley
Page Index Toggle Pages: 1