Inside() function inside mousePressed()


i am trying to setup a grid manually. the way is if mouseX and mouseY is inside the rects and the mouse is pressed set the cell = 1.

but if i put the function in the mousePressed() it doesn’t go. why?

 void testApp::draw(){
      for ( int i = 0; i < columns; i++) {
         for ( int j = 0; j < rows; j++) {


         if(board[i][j] == 1){
         else {
         ofRect(rects.x, rects.y, rects.width,  rects.height);

 void testApp::mousePressed(int x, int y, int button){
      for ( int i = 0; i < columns; i++) {
         for ( int j = 0; j < rows; j++) {

             if(rects.inside(mouseX, mouseY)){
             board[i][j] = 1;


everything that happens in your for loop stays in the stack of the loop and then gone, that is, your for loop in the draw and for loop in the mousecalls are two different situations ,… rects should be rects[i][j] or use board to do the comparisons not rect…

make a class that will have an ofRectangle in it,

make a 2dimentional vector of that class

or make a class row then a class column … and then a class grid…

ideally you should use the mouse listeners in that class

there are many examples out-there

I think I might have something similar with what your trying to do

in the addon.

try compiling that example… it’s super basic but might get you going in the right direction