"error on void " what is wrong?

hey guys. I am still on the beginner’s page and trying to figure out the OOP and the error hint keep telling me “error on void” and I have no idea where did I go wrong.

Bubble b1;
Bubble b2
  void setup() {
  size(600, 600);
  b1=new Bubble(10);
  b2=new Bubble(30);
}
void draw() {
  background(100, 20, 90);
  b1.display();
  b1.ascend();
  b1.top();
}

//the class bubble section as below:

class Bubble {
  float x;
  float y;
  float diameter;
   Bubble(float tempD){
    x=width/2;
    y=height;
    diameter=tempD;
  }
  void display() {
    fill(20, 20, 90);
    stroke(0);
    ellipse(x, y, diameter, diameter);
  }
  void ascend() {
    y--;
    x=x+random(-2,4);
  }
  void top(){if(y<0){y=y+hieght;}}
}

Missing ; here

You can tell from the wrong indent of void setup()

Warm regards,

Chrisir

Consider


if(y < -diameter) {
    y = height+diameter; // reset to bottom 
}

  • it’s height

  • and to make it look better, make sure bubble has left the screen entirely and is placed under the bottom of the screen entirely

1 Like

aha ! and SMH Siyue. I always made this type of mistake. Always. Unavoidable.
thank you Chris.
so there is an extension question: how do you figure out where is the problem when you saw this type of error hint. Since I am a careless person, I did read through it and I could not find the problem. is there any tricks or I just have to check it very carefully

1 Like

It’s a broad question.

  • here it was the wrong indent of the line void setup().

  • It was too far right.

  • In theory, when you write a line, read it and check it, if it’s correct. Directly after you’ve written it.

  • next step is to comment out chunks of code. When it runs, the last chunk contains the error.

that’s true also.