Keep getting void does not match with boolean error

edited October 2016 in Questions about Code
int s = 33;
int x = 27;
int y = 46;
boolean rectHitTest;

void draw() {
  background(200);
  if (squareHitTest(mouseX, mouseY, x, y, s)) {
    fill(255);
  } else {
    noFill();
  }
  rect(x, y, s -1, s - 1);



void squareHitTest(int a, int b, int c, int d, int e) {
  if ((a > e) && ( a < a + e) && (b > d) && ( b < d + e)) {
    rectHitTest = true;
  } else {
    rectHitTest = false;
  }
}

So I want to make the square fill white and return true when the mouse is inside the square, and no fil and return false when the mouse is outside the square? Any idea how to fix my code?

Tagged:

Answers

  • Answer ✓

    Line 8 is expecting a yes/no response from squareHitTest but line 17 says it returns nothing (void)

    Remove the global variable in line 4 and use return () to return the value.

  • Answer ✓

    You are also missing a } from the end of draw

Sign In or Register to comment.