Hey all! So halfway into development of this game, I got this error that I just can’t solve. I’m super new to C# as well so I might have written some unnecessary super long codes that could have been done in a single line. I’m getting there… hopefully.
So the error “IndexOutOfRangeException: Array index is out of range.” occurs at the line where I’ve written “ERROR HERE” (This is just for pointing out the location of the error is not actually in the code).
bool MakeOneMoveDownIndex(Tile[] LineOfTiles)
{
for (int i = 0; i < LineOfTiles.Length - 1; i++)
{
//MOVE BLOCK
if (LineOfTiles *.Number == 0 && LineOfTiles [i + 1].Number != 0)*
-
{*
_ LineOfTiles .Number = LineOfTiles [i + 1].Number;_
* LineOfTiles [i + 1].Number = 0;*
* return true;*
* }*
* //Blue + Red + Green = White*
_ else if (LineOfTiles .Number != 0 &&
LineOfTiles .Number == 33 /blue/ &&
ERROR HERE: LineOfTiles [i + 1].Number == 11 /red/ &&
LineOfTiles [i + 2].Number == 22 /green/ &&
LineOfTiles .mergedThisTurn == false && LineOfTiles [i + 1].mergedThisTurn == false && LineOfTiles [i + 2].mergedThisTurn == false)
* {
LineOfTiles .Number = 77; /white/
LineOfTiles [i + 1].Number = 0;
LineOfTiles [i + 2].Number = 0;
LineOfTiles .mergedThisTurn = true;
//GameOver();
return true;
}*
If you require any more code let me know because this error is in the 300s line. But I don’t think other lines of code are relevant to this error because they aren’t array related.
In the line after //MOVE BLOCK, I’ve tried changing this:
> if (LineOfTiles .Number == 0 && LineOfTiles [i + 1].Number != 0)
to this:
> if (LineOfTiles .Number == 0 && LineOfTiles [i + 2].Number != 0)
but it didn’t work…
Thanks for taking out the time to help me out! _