0

My code:

int blockspace = 3;
int blockx = 0;
int blocky = HEIGHT/4;

for (int i = 0; i < ROWS; i++){

    for (int j = 0; j < COLS; j++)
    {
        GRect block = newGRect(blockspace/2 + blockx, 0 + blocky, 40 - blockspace, 10 - blockspace);
        //adds block stuff..
    }
    blocky = blocky + 20;
}

Like the columns work perfectly, but the rows do not print!!! What is wrong with this, I see no errors! It complies and etc... (sorry about the formatting...)

1

I found the answer... I have no idea why though. By moving things around, I put int blockx = 0; inside the i loop. Why this matters, I have no idea and would like to know why! I know why now. Since blockx was not reset to 0, then blockx would be a value that is higher than the width of the window, hence my program did work, but the blocks would go like this

                =============

============

0

You don't change blockx in any place to make each brick go to the right. It should change in the inner for loop and then reset for the next row again. You can use the j variable instead if you want too.

8
  • I do change blockx, with setFilled(block, true); setColor (block, "BLACK"); add(window, block); blockx = blockx + (WIDTH/COLS); - I just didnt add it in to save space, like I said, the x spacing is ok and the j part of the loop works, NOT sure why the y part of the loop doesnt work though.. – Fijj Aug 5 '15 at 19:43
  • The values of WIDTH and COLS? – ChrisG Aug 5 '15 at 19:50
  • WIDTH = 400, COLS = 10 – Fijj Aug 5 '15 at 19:55
  • OH GOD, I got column and rows confused! It prints a line of blocks across the x axis of the window. – Fijj Aug 5 '15 at 19:57
  • Yeah I thought I had gotten it wrong. Ok, the value of HEIGHT? – ChrisG Aug 5 '15 at 19:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .