I’m trying to translate this AS3 script (from Lynda’s Dlash game development series) to Java:
if(allTiles.indexOf(allTiles[yPos - 1]) != -1 allTiles[yPos -1][xPos] == 0)
{
allTiles[yPos - 1][xPos] = 1;
allTiles[yPos][xPos] = 0;
tile.y -= tileW;
}
to
if (System.Array.IndexOf(allTiles, allTiles[yPos - 1]) != -1 allTiles[yPos - 1][xPos] == 0) {
allTiles[yPos - 1][xPos] = 1;
allTiles[yPos][xPos] = 0;
tile.transform.position.y += 12;
}
I’m not sure which part was wrong, but for some reason, it just kept returning me the error: IndexOutOfRangeException: Array Index is out of range.
I mean, the IndexOf function was suppose to check whether the value is in the Array right? And it should return me with either 0 or -1… instead, it gave me that error.
In case you’re confused, here’s the Array:
var arr : Array = [[1,1,1],[1,0,1],[1,1,1]];