hi guys i'm making a cube swapping game for my project at uni and i have a problem where my code tries to access an array address that doesnt exist, though im not sure how its accessing it. for some reason on the second or third pass it sets l,m and n to 5 and as my array is only 5x5x5 units long it cant find anything.
public void matchCheck()
{
int l;
int m;
int n;
//sweep x axis for matches
for (l = 0; l < 5; l++) // the letter k is unclean and must be purged
{
for (m = 0; m < 5; m++)
{
for (n = 0; n < 5; n++)
{
if (n > 0)
{
if (grid[n - 1, m, l] == grid[n, m, l] && xcombo < 6)
{
xcombo += 1;
}
else
{
switch (xcombo)
{
case 4:
Debug.Log("match 5" + cube[n - 1, m, l] + cube[n - 2, m, l] + cube[n - 3, m, l] + cube[n - 4, m, l] + cube[n - 5, m, l]);
grid[n - 1, m, l] = randomNumber();
grid[n - 2, m, l] = randomNumber();
grid[n - 3, m, l] = randomNumber();
grid[n - 4, m, l] = randomNumber();
grid[n - 5, m, l] = randomNumber();
xcombo = 0;
refreshGrid();
break;
case 3:
Debug.Log("match 4" + cube[n - 1, j, l] + cube[n - 2, j, l] + cube[n - 3, j, l] + cube[n - 4, j, l]);
grid[n - 1, m, l] = randomNumber();
grid[n - 2, m, l] = randomNumber();
grid[n - 3, m, l] = randomNumber();
grid[n - 4, m, l] = randomNumber();
xcombo = 0;
refreshGrid();
break;
case 2:
Debug.Log("match 3" + cube[n - 1, j, l] + cube[n - 2, j, l] + cube[n - 3, j, l]);
grid[n - 1, m, l] = randomNumber();
grid[n - 2, m, l] = randomNumber();
grid[n - 3, m, l] = randomNumber();
xcombo = 0;
refreshGrid();
break;
}
Debug.Log("combo" + xcombo);
xcombo = 0;
refreshGrid();
}
}
}
n = 0;
}
m = 0;
xcombo = 0;
}
}
refreshGrid()doing?grid[...]in the respective cycle?