Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript/jQuery-数组列表不会贯穿整个系统_Javascript_Jquery_Html - Fatal编程技术网

JavaScript/jQuery-数组列表不会贯穿整个系统

JavaScript/jQuery-数组列表不会贯穿整个系统,javascript,jquery,html,Javascript,Jquery,Html,因此,我正在使用A*寻路。我让它工作,但它不工作的所有方式。它一直工作到右边的最后一列4。奇怪 它一直工作到X小于等于10。这很奇怪,因为Y的最大值是10。也许是在一起?我不知道。但是我的地图是15列乘10行。以下是一个在线示例: 我得到的一个有趣的错误是uncaughttypeerror:无法读取未定义的属性“8” 8是您单击的位置的Y。如果单击a,则显示右侧的第一个灰色块(因为第0行被隔离)。然后8会说1 这是它布置节点的部分 // Creates a Graph class used in

因此,我正在使用
A*寻路
。我让它工作,但它不工作的所有方式。它一直工作到右边的最后一列
4
。奇怪

它一直工作到X小于等于10。这很奇怪,因为
Y
的最大值是
10
。也许是在一起?我不知道。但是我的地图是
15列
10行
。以下是一个在线示例:

我得到的一个有趣的错误是
uncaughttypeerror:无法读取未定义的属性“8”

8
是您单击的位置的
Y
。如果单击a,则显示右侧的第一个灰色块(因为第0行被隔离)。然后
8
会说
1

这是它布置节点的部分

// 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;
}
如您所见,它有15列,向下10行

我做错了什么

更新新内容

for (y = 0; y <= 10; y++) {

    row = grid[y];
    nodes[y] = new Array(15);

    for (x = 0; x <= 15; x++) {

        console.log("X: " + x + " Y: " + y);
        //console.log("Row: " + row[x]);
        nodes[x][y] = new GraphNode(x, y, row[x]);
    }
}

对于(y=0;y你的
x
y
命名法是错误的

x
轴应该是表中的第二个维度,例如
节点[y][x]

for (y = 0; y <= 10; x++) {
    row = grid[y];
    nodes[y] = [];
    for (x = 0; x <= 15; x++) {
        nodes[y][x] = new GraphNode(x, y, row[y]); 
    }
}

for(y=0;y对,我知道。我像这样尝试了。我的游戏被卡住了。页面从未完成加载,Chrome的控制台从未加载。\@weka它在Chrome 18上为我加载,但停止工作(没有错误)只要我点击最左边的10列。嗯。是的,但这就是我试图解决的问题。为什么我不在右边的5列上工作。@weka-因为你把
x
y
混在一起了-不是在这里,而是在代码的其他部分!例如
graph.nodes[x_block][y_block]
我用新格式编辑了我的答案。它仍然给我错误。无法将0设置为未定义。
for (y = 0; y <= 10; x++) {
    row = grid[y];
    nodes[y] = [];
    for (x = 0; x <= 15; x++) {
        nodes[y][x] = new GraphNode(x, y, row[y]); 
    }
}