# I need help changing values in an array

**URL:** <https://discourse.processing.org/t/i-need-help-changing-values-in-an-array/18586>\
**Category:** Coding Questions\
**Created:** [March 11, 2020, 3:30am UTC](https://discourse.processing.org/t/i-need-help-changing-values-in-an-array/18586 "2020-03-11T03:30:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricochet1451](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@Ricochet1451](https://discourse.processing.org/u/Ricochet1451)\
**Post date:** [March 11, 2020, 3:30am UTC](https://discourse.processing.org/t/i-need-help-changing-values-in-an-array/18586/1 "2020-03-11T03:30:12Z")

</div>

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.

Thanks.

[https://editor.p5js.org/ricochet1451/sketches/uJQ68Klu](https://editor.p5js.org/ricochet1451/sketches/uJQ68Klu)

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 11, 2020, 6:58am UTC](https://discourse.processing.org/t/i-need-help-changing-values-in-an-array/18586/2 "2020-03-11T06:58:14Z")

</div>

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]!

---

<div class="post-metadata">

**Author:** ![Ricochet1451](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@Ricochet1451](https://discourse.processing.org/u/Ricochet1451)\
**Post date:** [March 11, 2020, 4:01pm UTC](https://discourse.processing.org/t/i-need-help-changing-values-in-an-array/18586/3 "2020-03-11T16:01:39Z")

</div>

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.

 ![whyy](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/47bc50b186c7349859be46e5fee26edc740edf11.png)
