Simple coding question (= vs ==)

edited December 2016 in Questions about Code

why does this change the boolean to true without mouse clicking?

I know the fix to the problem is to just use if (button), but why does if (button=true) make the boolean true?

boolean button = false;

int circleX = 0;
int circleY = 100;

void setup() {
  size(200, 200);
}

void draw() {
  background(100);
  stroke(255);
  fill(0);
  ellipse(circleX, circleY, 50, 50);

  if (button = true) {
    circleX = circleX + 1;
  }


}



void mousePressed() {
  button = !button;
}
Tagged:
Sign In or Register to comment.