我在nodejs有个情况。我想基于给定的点生成一个特殊值的字段。下面是一个例子:
[
[".", "#", "#", "#", "."],
[".", "#", "?", "#", "."],
[".", "#", "#", "#", "."],
]
然后会变成
[
"#", "#", "#",
"#", "?", "#",
"#", "#", "#"
]
我写了一些函数。下面是第一个生成巨大数组(2d格式)的:
for(i = 0; i < 100; i++) {
var r = [];
for(i2 = 0; i2 < 100; i2++) {
r.push({
RenderToken: ".",
Type: level.LT_GROUND //a string
});
}
level.level.push(r); //level.level is an array
r = [];
}
这是一个特殊的函数。
const limx = client.Renderer.limitX; // an int (width of view from target)
const limy = client.Renderer.limitY; //an int (height of view from target pos)
var xa = [];
for(i2 = client.Position.x - limx; i2 < client.Position.x + limx + 1; i2++) {
for(i3 = client.Position.y + limy; i3 > client.Position.y - limy; i3--) {
if(i2, i3 > 0) {
xa.push(level.level[i3][i2].RenderToken); //!! ERROR level.level is an array
}
}
xa.push("\n");
} //xloop
注意,我想 client.Position.x, client.Position.y
永远是中心点。
预期结果:一个带有 ?
在中间(客户机,位置,X,客户机,位置,Y)
实际结果:
请参阅错误消息
TypeError: Cannot read property 'RenderToken' of undefined
at Object.renderPers (C:\Users\##\Desktop\libraries\##\##\ui.js:88:49)
at ReadStream.<anonymous> (C:\Users\##\Desktop\libraries\##\##\io.js:47:16)
at ReadStream.emit (events.js:315:20)
at emitKeys (internal/readline/utils.js:345:14)
at emitKeys.next (<anonymous>)
at ReadStream.onData (readline.js:1144:36)
at ReadStream.emit (events.js:315:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at ReadStream.Readable.push (internal/streams/readable.js:223:10)
我已经重写了这个函数好几次,并尝试了“逐个关闭”循环问题。到目前为止,一切似乎都不起作用。
代码:参见上面的代码
编辑:
添加了错误产生的位置
暂无答案!
目前还没有任何答案,快来回答吧!