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 › Re: Unexpected token:boolean issue.
Page Index Toggle Pages: 1
Re: Unexpected token:boolean issue. (Read 1918 times)
Re: Unexpected token:boolean issue.
May 22nd, 2010, 3:11pm
 
but the problem IS in the code preceding the declaration of this function. This functions code's fine.
Re: Unexpected token:boolean issue.
Reply #1 - May 22nd, 2010, 3:13pm
 
No idea, except perhaps: do you have a setup() method?
Re: Unexpected token:boolean issue.
Reply #2 - May 22nd, 2010, 3:30pm
 
Quote:
It was working and while testing another part of the code I got this error but now as I have already said it seems the problem is in this particular section of code.


If it was working and now it doesn't work but you haven't modified this function then the function cannot be the cause.

I managed to duplicate the error with the following code
Code:

void setup(){
}

void dummy(){

boolean rectCircleIntersect(float rx, float ry, float rw, float rh, float cx, float cy, float cr)
 {

   float circleDistanceX = abs(cx - rx - rw/2);
   float circleDistanceY = abs(cy - ry - rh/2);

   if (circleDistanceX > (rw/2 + cr)) {
     return false;
   }
   if (circleDistanceY > (rh/2 + cr)) {
     return false;
   }
   if (circleDistanceX <= rw/2) {
     return true;
   }
   if (circleDistanceY <= rh/2) {
     return true;
   }

   float cornerDistance = pow(circleDistanceX - rw/2, 2) + pow(circleDistanceY - rh/2, 2);
   return cornerDistance <= pow(cr, 2);
 }
}


Is this code the method has been accidentally embedded in the dummy method. I would check out your {}
Re: Unexpected token:boolean issue.
Reply #3 - May 22nd, 2010, 8:03pm
 
Yeah that makes alot of sense quark.
There was a problem with my {}s in the draw function.
Now it can't find the mover class.

Here is the rest of the sketch

- mover tab -

Code:
class Mover
{
 int mr = 8; //mover radias
 PVector location;
 PVector velocity;
 PVector acceleration;
 float topspeed;
 
 Mover()
 {
   location = new PVector(width/2,height/2);
   velocity = new PVector(0,0);
   acceleration =  new PVector(0,0);
   topspeed = 5;
 }
 
 void update(char x)
 {
   
   if(x == 'w' || x == 'W')
   {
     acceleration.y = -10;
   }
   else if (x == 's' || x == 'S')
   {
     acceleration.y = +5;
   }
   else if (x == 'a' || x == 'A')
   {
     acceleration.x = -5;
   }
   else if (x == 'd' || x == 'D')
   {
     acceleration.x = +5;
   }
   
     
   velocity.add(acceleration);
   velocity.limit(topspeed);
   location.add(velocity);
   
 }
 
 void gravity()
 {
  //acceleration.y = 5;  
 
  velocity.add(acceleration);  
  velocity.limit(topspeed);
  location.add(velocity);
 }




 void display()
 {
   stroke(0);
   fill(230,0,140);
   ellipse(location.x,location.y,16,16);
   fill(100,0,200);
   ellipse((location.x - 3 ),(location.y -3 ),3,3);
   ellipse((location.x + 3 ),(location.y -3 ),3,3);
     
 }
 
 void checkEdges()
 {
 
   //Dealing with collision with a rectangle not the edges
   
   if(rectCircleIntersect( 30, 300, 40, 50, location.x, location.y, mr) == true)
   {    
      // X collison is working by itself.
     
         if(location.x >= (30 - mr) && location.x <= 50 )
       {
         location.x = (30 - mr);
         
       }  
        else if(location.x < (70 + mr) )
       {
          location.x = (70 + mr);  
                     
       }
      ///////////
     
      // Y collison is working by itself.
               
       if(location.y >= (300 - mr) && location .y <= 325 )
       {
          location.y =  (300 - mr);
       }
       else if(location.y < (350 + mr) )
       {
          location.y = (350 +mr);
       }
      /////////
             
   }
     
     // the edges
     
   if (location.x >= (width - mr))
   {
     location.x = (width - mr);
   }
   else if (location.x <= mr)
   {
     location.x = (mr);
   }

   if (location.y >= (height - mr))
   {
     location.y = (height - mr);
   }
   else if (location.y <= mr)
   {
     location.y = (mr);
   }
   
 }

}

boolean rectCircleIntersect(float rx, float ry, float rw, float rh, float cx, float cy, float cr)
{
 
 float circleDistanceX = abs(cx - rx - rw/2);
 float circleDistanceY = abs(cy - ry - rh/2);
 
 if (circleDistanceX > (rw/2 + cr)) { return false; }
 if (circleDistanceY > (rh/2 + cr)) { return false; }
 if (circleDistanceX <= rw/2) { return true; }
 if (circleDistanceY <= rh/2) { return true; }
 
 float cornerDistance = pow(circleDistanceX - rw/2, 2) + pow(circleDistanceY - rh/2, 2);
 return cornerDistance <= pow(cr, 2);
}


-main tab-
Code:
Mover mover;

void setup()
{
 size(400,400);
 mover = new Mover();
}
void draw()
{
 
 background(230,100,00);
 rect(30, 300, 40,50);
 mover.checkEdges();
 mover.display();
 mover.gravity();
 
while(keyPressed)
{
  char x = key;
  mover.update(x);      
}


It's pretty messy I left a few things unfinished because I was getting stuck.


Re: Unexpected token:boolean issue.
Reply #4 - May 22nd, 2010, 11:58pm
 
I think you are missing a closing '}' at the end of your draw method
Re: Unexpected token:boolean issue.
Reply #5 - May 23rd, 2010, 3:24am
 
yup..

I think it's pretty safe to say that when it "can't find classes" or throws a unexpected token error on the function declaration, the code BEFORE is probably broken, taken that you checked for the most obvious mistakes.
Page Index Toggle Pages: 1