Hey guys,
I’m having this really obnoxious bug in a 2d array. Getting array data only works when searching with a positive increment.
Find Grid Code:
public static Grid getGrid(float x, float y) {
Grid r = null;
try {
r = channels[(int) x][(int) y];
} catch (ArrayIndexOutOfBoundsException e) {
r = new Grid();
}
return r;
}
Here is where the problem is:
public void findNeighbors() {
if (!found) {
north = Game.getGrid((int) position.x / 10, (int) (position.y / 10) - 1);// not
// working
east = Game.getGrid((int) position.x / 10 + 1, (int) position.y / 10);// working
west = Game.getGrid((int)( position.x / 10) - 1, (int) position.y / 10);// not
// working
south = Game.getGrid((int) position.x / 10, (int) position.y / 10 + 1);// working
found = true;
}
}
The program is only working when getting the east and south tiles.
I just don’t understand why this could be happening.