Unexpected token - void

This errors shows for no reason, in first tab

Drop[] drops = new Drop[500]

void setup() {
  size(640, 360) ;
  for (int i = 0; i < drops.length; i++) {
    drops[i] i = new Drop() ;
  }
}

void draw() {
  background(230, 230, 250)
  for (int i = 0; i < drops.length; i++) {
   drops[i].fall() ;
   drops[i].show() ;
  }
}

second tab

class Drop {
  float x = random(width) ;
  float y = random(-500, -50) ;
  float z = random(0, 20) ;
  float len = map(z, 0, 20, 10, 20) ;
  float yspeed = map(z, 0, 20, 1, 20) ;
  float len - random(10, 20) ;
  
  void fall() {
    y = y + yspeed
    float grav = map(z, 0, 20, 0, 0.2) ;
    yspeed = yspeed + grav;
  
    if (y > height) {
      y = random(-200, -100) ;
      yspeed = map(z, 0, 20, 4, 10) ;
    }
  }
  
  void show() {
    stroke(138, 43, 226) ; 
    line(x,y,x,y+len) ;
  }
}

pls

  • format your code in Processing IDE [crtl][t]
  • paste here at your above post by using

</>

code formatter

usually you write code line by line
so only one can be wrong
so a code like that could never happen???

// https://discourse.processing.org/t/unexpected-token-void/8099

Drop[] drops = new Drop[500];   // ; needed

void setup() {
  size(640, 360);
  for (int i = 0; i < drops.length; i++) {
    //    drops[i] i = new Drop() ;
    drops[i] = new Drop();
  }
}

void draw() {
  background(230, 230, 250);   // ; needed
  for (int i = 0; i < drops.length; i++) {
    drops[i].fall();
    drops[i].show();
  }
}

//second tab
class Drop {
  float x = random(width);
  float y = random(-500, -50);
  float z = random(0, 20);
  float len = map(z, 0, 20, 10, 20);
  float yspeed = map(z, 0, 20, 1, 20);
//  float len - random(10, 20) ;   // can only have one declaration of a variable!

  void fall() {
    y = y + yspeed;   // ; needed
      float grav = map(z, 0, 20, 0, 0.2);
    yspeed = yspeed + grav;

    if (y > height) {
      y = random(-200, -100);
      yspeed = map(z, 0, 20, 4, 10);
    }
  }

  void show() {
    stroke(138, 43, 226);
    len -= random(10, 20);          // add here ??
    line(x, y, x, y+len);
  }
}

Each line needs to finish with a semi-colon aka ;

This does not apply to if-else, while() or for() loops.

Kf

Thank You! I just wanted to make a “rain” and i didn’t tought that i willl get a mistake like this