学校のプロジェクトでタイル ベースのゲームを作成する必要があり、解決できないような「重大な」エラーが発生しました。
これは私のスクリプトです:
function init(){
var speelVeldBreedte;
var speelVeldHoogte;
var speelVeld = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1],
[1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1]
];
var speelTerrein = document.getElementById("speelterrein");
}
speelVeldBreedte=speelVeld[0].length;
speelVeldHoogte=speelVeld.length;
var schaalTerrein = 20;
speelTerrein.width = speelVeldBreedte * schaalTerrein;
speelTerrein.height = speelVeldHoogte * schaalTerrein;
var ctx = speelTerrein.getContext("2d");
ctx.fillStyle = "white";
ctx.fillRect(0,0,speelTerrein.width,speelTerrein.height);
for (var y=0; y<speelVeldHoogte;y++){
for (var x=0;x<speelVeldBreedte;x++){
var steen = speelVeld[y][x];
if (steen> 01){
ctx.fillStyle = "rgb(100,0,0)";
ctx.fillRect(x*schaalTerrein,y*schaalTerrein,schaalTerrein,schaalTerrein);
}
}
}
これは私が得ているエラーです:
uncaughtReferenceError: speelVeld is not defined.
これは32行目を指します:
speelVeldBreedte=speelVeld[0].length;
誰かがこのエラーを解決する方法と正確に何が問題なのか教えてくれることを願っています.
前もってありがとう、レミー