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
Page Index Toggle Pages: 1
unexpected token: void (Read 316 times)
unexpected token: void
Dec 10th, 2008, 8:26pm
 
can't figure out why it's giving me this


code:


PImage img;       // The source image
PImage img1;    
PImage img2;
int cellsize = 5; // Dimensions of each cell in the grid
//int cols, rows;   // Number of columns and rows in our system
int cols = width;
int rows = height;
int speed = 0;
int gravity = 1;
/*int [][] pixelLoc = new int [cols][rows];
boolean [] wasTouched = new boolean [cols*rows];
boolean a = true;
*/
float distance = dist(x,y,mouseX,mouseY);

Pixel pixel1;




void setup() {
 size(600,450,P3D);
 frameRate(30);
 img1 = loadImage( "layer.jpg" );
 img2 = loadImage( "black.jpg" );

 img = loadImage( "grey.4.jpg" ); // Load the image

   cols = width/cellsize;              // Calculate # of columns
 rows = height/cellsize;             // Calculate # of rows
 pixel1 = new Pixel(distance);
}

void draw() {


 background(img1);
 img2.loadPixels();
 img.loadPixels();
 // frameRate(.8);

 // Begin loop for columns
 for (int i = 0; i < cols; i++ ) {
   // Begin loop for rows
   for (int j = 0; j < rows; j++ ) {
     int x = i*cellsize + cellsize/2; // x position
     int y = j*cellsize + cellsize/2; // y position
     int loc = x + y*width;           // Pixel array location
     color c = img.pixels[loc];       // Grab the color
     //float distance = dist(x,y,mouseX,mouseY);
     // int z = 0;

     // Calculate a z position as a function of mouseX and pixel brightness
     float z = (mouseX/(float)width) * brightness(img.pixels[loc])- 100.0;

     /*
     if (distance <= 10  && mousePressed == true) {
      y = y + speed;
      speed = speed + gravity;
     
     /*  if (y > height) {
      speed = speed * -1;
      y = height;
     
      }*/
     /*    if (y > height) {
      speed = speed * -1;
      y = height;
      }*/


   }




 }

 // Translate to the location, set fill and stroke, and draw the rect
 pushMatrix();
 translate(x,y,z);
 fill(c);
 noStroke();
 rectMode(CENTER);
 rect(2,10,cellsize,cellsize);
 popMatrix();

 pixel1.fall();
 pixel1.move();
 pixel1.display();




 for (int i = 0; i < cols; i++ ) {
   // Begin loop for rows
   for (int j = 0; j < rows; j++ ) {
     int x = i*cellsize + cellsize/2; // x position
     int y = j*cellsize + cellsize/2; // y position
     int loc = x + y*width;           // Pixel array location
     color c = img2.pixels[loc];       // Grab the color

     // Calculate a z position as a function of mouseX and pixel brightness
     float z = (mouseX/(float)width) * mouseY/(img2.pixels[loc])- 50.0;//brightness(img2.pixels[loc])- 100.0;


     // Translate to the location, set fill and stroke, and draw the rect
     pushMatrix();
     translate(x,y,z);
     fill(c);
     noStroke();
     rectMode(CENTER);
     rect(0,0,cellsize,cellsize);
     popMatrix();

   }
 }
}



class Pixel {

 float r;   // radius
 float x,y; // location
 float xspeed,yspeed; // speed

   // Constructor
 Pixel(float tempR) {
   r = tempR;
   x = random(width);
   y = random(height);
   xspeed = random( - 5,5);
   yspeed = random( - 5,5);
 }


 void fall() {
   float distance = dist(x,y,mouseX,mouseY);

   if (distance <= 10  && mousePressed == true) {
     y = y + speed;
     speed = speed + gravity;


   }


   void move() {
     x += xspeed; // Increment x
     y += yspeed; // Increment y

     // Check horizontal edges
     if (x > width || x < 0) {
       xspeed *= - 1;
     }
     //Check vertical edges
     if (y > height || y < 0) {
       yspeed *= - 1;
     }

   }




 }

sorry for the mess
Re: unexpected token: void
Reply #1 - Dec 10th, 2008, 9:07pm
 
I noticed your fall method doesn't have a closing brace dealie. } But I think there are some variable scope problems beyond that. Sorry, I was kind of just glancing at it.
Re: unexpected token: void
Reply #2 - Dec 11th, 2008, 2:33am
 
vortdog wrote on Dec 10th, 2008, 8:26pm:
sorry for the mess


yes, it's the fall() closing bracket

it always pays to tidy things up. if you did that it would be easy to spot the problem.

Re: unexpected token: void
Reply #3 - Dec 11th, 2008, 2:49am
 
I had that error. Move all the code you can into setup() instead of before it.  I think specifically anything with "new" in it needs to be in setup(). Not sure but that worked for me.
Page Index Toggle Pages: 1