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 › unexpected token: void (also...)
Page Index Toggle Pages: 1
unexpected token: void (also...) (Read 582 times)
unexpected token: void (also...)
Dec 11th, 2008, 3:02am
 
Hi there ! I'm still trying to begin in processing (and I get some problem)

I get a "unexpected token:void" error on the "void draw" of the main part, and I don't understand why °_° so if anyone can give me a hand, I would love that, cause I don't know what to do.

here is the main part :

Boule[] boules = new Boule[20];

float[] x = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] y = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] r = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] m = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

float xv;      
float yv;


int x_ecran = 400 ;
int y_ecran = 400 ;
int xMilieu = 300;
int yMilieu = 300;

int a;
int b;


float gravite;



void setup() {
 size(x_ecran,y_ecran);
 smooth();
 
 x[0]=100;
 x[1]=150;
 
 y[0]=150;
 y[1]=220;
 
 r[0]=50;
 r[1]=12;
 
 m[0]=7;
 m[1]=1;
 
for(int i=0; i<boules.length; i++){
     float r_init = r[i];
     float x_init = x[i];
     float y_init = y[i];
     float m_init = m[i];
     boules[i] = new Boule(r_init, x_init, y_init, m_init); }  
 

 gravite = .015;

void draw() {
 background(255);
 
for(int i=0; i<boules.length; i++){

 boules[i].bouge();
 
 a = i;
 b = i;
 a != b;
 
 boules[a].appliquerGravite(boules[b]);

 boules[i].rebondir_ecran();

 boules[i].dessine();
}
}







and also, I don't know if it can be related to this but here is the "boules" class part :






class Boule {
 
 float r;    // rayon
 float x,y; // position

 color c = color(0,0);
 
 float xv = 0;       //vélocité actuelle le long de l'axe des x
 float yv = 0;       //vélocité actuelle le long de l'axe des y
 
 float xd;        // Distance to target along x axis
 float yd;        // Distance to target along y axis
 float d;  // Distance to target
 
 float gAngle;  
 float gTheta;   //angle en radians
 float gxv;      // gravité en x
 float gyv;      // gravité en y
 float m;      // masse particule
   


void appliquerGravite(){
   gAngle     = calculAngle(x, y, f.x, f.y);
   gTheta     = (-(gAngle * PI))/180;
   gxv        = cos(gTheta) * (-gravite/(r/6));
   gyv        = sin(gTheta) * (-gravite/(r/6));
   
   
   f.xv += m*f.gxv;
   f.yv += m*f.gyv;
   xv += m*gxv;
   yv += m*gyv;
 }
   
   void bouge(){
   
   x       +=   xv; //incr&#65533;mente x equivalent a x = x +xspeed
   y       +=   yv;
   
 }
   
 void rebondir_ecran(){
 
      if (x > x_ecran-50){
        xv = xv-(4/r);}
      if(x < 50){
        xv = xv+(4/r);}
       
      if (y > y_ecran-50){
        yv = yv-(4/r);}
      if(y < 50){
        yv = yv+(4/r);}
      }
 
 
  void rebondir(){
 
  xv    *=    -1;
  yv    *=    -1;
  f.xv  *=    -1;
  f.yv  *=    -1;
  }
  void allume (){
 
 c = color(150,50);
 xd = x - f.x;
 yd = y - f.y;
 
 
  }
 
   boolean approche() {
 
 float distance = dist(x,y,f.x,f.y);
 
   calculDistance(x, y, f.x, f.y);
     if (d < 2*r + 2*f.r) {
     return true;
   } else {
     return false;
   }
 }
 
  boolean intersect() {
 
   calculDistance(x, y, f.x, f.y);
     if (d < r + f.r) {
     return true;
   } else {
     return false;
   }
 }
 
 void dessine () {
 
  noStroke();
  fill(c);
  ellipse(x,y,r*2,r*2);
  c = color(0,0,0,128);
     }
     
float calculDistance(float x1, float y1, float x2, float y2){
 xd = x1 - x2;
 yd = y1 - y2;
 d = sqrt(xd * xd + yd * yd);
 return d;
 
}


float calculAngle ( float x1, float y1, float x2, float y2){
   float  xd = x1 - x2  ;
   float  yd = y1 - y2   ;
 
float t = atan2 (yd,xd);
float a =(180 + (-(180*t) / PI));
return a;
}
}
Re: unexpected token: void (also...)
Reply #1 - Dec 11th, 2008, 10:44am
 
Tiens, un Français... ^_-

The setup() routine is missing a closing brace before the draw() routine definition.
Reminder: when you are on a brace, the matching one is highlighted. Helps in catching such errors...

Oh, and avoid using variables with size(). Put hard-coded values there and use width and height predefined variables elsewhere.
Re: unexpected token: void (also...)
Reply #2 - Dec 11th, 2008, 3:46pm
 
waaaaa shame on me -_- I forget a }, it was too late yesterday to work for me , thanks a lot dude ! and thanks also for your advices !

trop de cafe tue le cafe (et la tete avec ^^)
Re: unexpected token: void (also...)
Reply #3 - Dec 11th, 2008, 5:54pm
 
Wo I got a new problem -_- (a common beginner's life)

In fact, I created a list a 20 objects, and then I would like each object to apply a fonction (appliquerGravite) on every others, so here is how It tried to do that :

in the main part (I just show the concerned part):

Boule[] boules = new Boule[20];

float[] x = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] y = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] r = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] m = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

int a;
int b;

(...)

void draw() {
 background(255);
 
for(int i=0; i<boules.length; i++){
 
 a = i;
 b = i;
 a != b;
 
 boules[a].appliquerGravite(boules[b]);

}
}




and in the class Boule part :




class Boule {

void appliquerGravite(boules[b]){
   gAngle     = calculAngle(x, y, x[b], y[b]);
   gTheta     = (-(gAngle * PI))/180;
   gxv        = cos(gTheta) * (-gravite/(r/6));
   gyv        = sin(gTheta) * (-gravite/(r/6));


}

so in this way I try to make Boule[a] apply a fonction on Boule[b] (where boule[a] is every Boule and Boule[b] is also every Boule object but the [a] one, I just don't want objects to apply this fonction to themselves)

But when I try to run it, processing say that He don't like the way I wrote boule[b] in
"void appliquerGravite(boule[b])"

(it says "syntax error, maybe a missing ] character ? )

Am I using the right way to do that kind of stuff ?
Re: unexpected token: void (also...)
Reply #4 - Dec 11th, 2008, 8:12pm
 
It seems to me that instead of using arrays for x, y, r, and m, these should be members of your Boule class.

Also, no that's not how you define a class method, or any function for that matter.

In the parameter list (the stuff between the parentheses) you first give a type and then a name that you will refer to the variable as.  So in your case it would look like:

void appliquerGravite(Boule some_boule){

}

obviously you can change some_boule to whatever you want to call it.

i suggest you read a tutorial on OOP. here is one:
http://java.sun.com/docs/books/tutorial/java/concepts/index.html
Re: unexpected token: void (also...)
Reply #5 - Dec 11th, 2008, 8:44pm
 
Thnaks rebirth, I'll try it, and sure have a look to the tutorials :)
Page Index Toggle Pages: 1