I need help changing values in an array

I am currently trying to make a chess game. But i am having some issues changing values. If you look on line 214 of sketch, i am trying to set the pawn to the upper right to “available”, but it wont let me change the value. It works on line 217 where i set the value to the upper left to available. If you move one of the middle white pawns towards the black pawns you can see what i mean (hopefully). I am confused as to why this is happening.



1 Like

Your grid is 64 Cells, in an 8 by 8 array.

You have two loops near line 214, one for x and one for y.
Each loop goes from 0 to 7, so the values for x and y range from 0 to 7.

But then you try to access things like grid[x+1][y-1]. If x is 7, x+1 is 8, but you can’t access grid[8][y-1] because the array only goes up to grid[7][y-1]!

1 Like

I have not yet implemented the edge cases like you mentioned above, but even when i try to change grid[x+1][y-1] when x is 4 and y is 2, it only works for the values that come before it in the loop. This can be seen when i try and set all of the cells in a 2 cell radius around the piece.