If statement problems

Hello, I am new to processing and programming in general, as of a project for school I ran into a problem.

The goal is that a random number will be generated, with a click on a the mouse, after that it should go to the specific if statement and do those tasks.

Now the problem is that the random number will be generated, but that only the first if statement does what it is supposed to do, and that is show the rectangle. can you guys help?

class Fish {
int jumpPosition;
int test;
void fishJump() {

if (mousePressed) {
  jumpPosition =  int(random(4));
  println(jumpPosition);
}
if (jumpPosition == 0) {
  fill(255);
  rect(250, 250, 50, 50);
} 
if (jumpPosition == 1);
{  
  fill(255);
  rect(750, 250, 100, 100);
} 
if (jumpPosition == 2);
{  
  fill(255);
  rect(250, 750, 100, 100);
} 
if (jumpPosition == 3);
{   

  fill(255);
  rect(750, 750, 100, 100);
}

}
}

your error are the ; signs after the if-clauses. They close the if-clause.

Without the ; signs, the if-clause extends to the {…} section. That’s what you want.

1 Like

this will execute multiple times because it registers a mouse press multiple times

instead use the function mousePressed() (same name, different thing)

void mousePressed() {
  jumpPosition =  int(random(4));
}
1 Like

and welcome to the forum!

Great to have your here!

1 Like

Thank you very much for your help.

1 Like