mousePressed not updating in while loop

Glad you found a solution.

That is correct – and true for the whole event model. draw() renders the frame, and then then keyboard, mouse, and various post- event updates from any libraries you are using are all processed. frameCount increments, pre-events are called, draw renders again, et cetera. In general, this is why delaying within draw often fails to work as a debugging method – although I have also been down that rabbit hole.

There are some other things that have similar behavior that might be surprising. For example, exit() might surprise you – try running this sketch:

void draw(){
  exit();
  println("hello world");
}

For discussion of that one, see:

1 Like