So, I’m working with A* Pathfinding. I got it working however it doesn’t work all the way. It works all the way until the last 4 columns to the right. Weird.
It works all the way until X is 10 or less. Which is weird because Y‘s max is 10. Maybe it’s together? I don’t know. But my map is 15 columns by 10 rows. Here is an online example: http://mystikrpg.com/html5/
Try clicking on the right side of the map, see how it doesn’t work? Now try clicking somewhere so Xis either 10 or below. It works, as it should.
An interesting error I get is Uncaught TypeError: Cannot read property '8' of undefined.
The 8 is the Y of where you clicked. If you click a the very first gray block on the right-side (since row 0 is walled off). Then that 8 would say 1.
Here’s the part where it lays out the nodes.
// Creates a Graph class used in the astar search algorithm.
function Graph(grid) {
var nodes = [];
var row, rowLength, len = grid.length;
for (x = 0; x <= 10; x++) {
row = grid[x];
nodes[x] = new Array(15);
for (y = 0; y <= 15; y++) {
nodes[x][y] = new GraphNode(x, y, row[y]);
}
}
this.input = grid;
this.nodes = nodes;
}
Your
loadmapfunction returns an array of 11 elements.And when
x_blockis 13 for example,graph.nodes[x_block][y_block]returns undefined.