我一直试图解决这个问题几个小时,但我绝对没有运气。
程序运行第一次迭代没有任何问题(数字正确拼接到数组中,结果完美打印到控制台)但在第二次运行时出现此错误:
未捕获的类型错误:无法调用未定义的方法“拼接”
此时,控制台日志中根本没有打印任何内容。
这是第一个功能:
var gameRound = [
[],
[]
];
fight();
function fight() {
var r = 10;
var towel = false;
var i = 1;
while (i <= r && towel == false) {
round(i);
console.log("ROUND ", i);
console.log(boxerA[0]);
console.log("Punches Thrown: ", gameRound[i][0]);
console.log("Punches Landed: ", gameRound[i][1]);
console.log("Jabs Thrown: ", gameRound[i][2]);
console.log("Jabs Landed: ", gameRound[i][3]);
console.log("Power Thrown: ", gameRound[i][4]);
console.log("Power Landed: ", gameRound[i][5]);
console.log("Fatigue: ", boxerA[28]);
console.log("Damage: ", boxerA[29]);
console.log(boxerB[0]);
console.log("Punches Thrown: ", gameRound[i][6]);
console.log("Punches Landed: ", gameRound[i][7]);
console.log("Jabs Thrown: ", gameRound[i][7]);
console.log("Jabs Landed: ", gameRound[i][9]);
console.log("Power Thrown: ", gameRound[i][10]);
console.log("Power Landed: ", gameRound[i][11]);
console.log("Fatigue: ", boxerB[28]);
console.log("Damage: ", boxerB[29]);
i++;
}
}
以及列出错误的函数和行:
function round(i)
{
// ...
gameRound[i].splice(0,0,numPunchesTA,numPunchesLA,numJabsTA,numJabsLA,numPowerTA, numPowerLA, numPunchesTB, numPunchesLB,numJabsTB,numJabsLB,numPowerTB,numPowerLB);
}
当我测试它时,变量i
仍然计数为“2”,所以我不确定为什么下一行没有被拼接到数组中。