我最近在p5js网络编辑器上编写了一个代码,当我尝试复制代码并将其粘贴到应用程序中时,它显示错误
我试图整理代码仍然不起作用。
应用可能太旧了
我只会粘贴整个代码,因为idk错误所在
unction draw() {
background(220);
seconds = time / 100;
time = time + popo;
fill(112, 166, 255);
text(start, po, pi);
fill(178, 178, 178);
rect(x, y, 20, 20);
fill(255, 99, 99);
triangle(x1, y1, x2, y2, x3, y3);
console.log(seconds);
x1 = x1 + trianglespeed;
x2 = x2 + trianglespeed;
x3 = x3 + trianglespeed;
input.attribute('placeholder', "Enter speed");
input.position(0, 410);
if (!(input.value() >= 0)) {
input.value("");
}
if (playing == true) {
if (x1 <= 70) {
trianglespeed = 0;
fill(112, 166, 255);
text("You lost.", 200, 200);
x1 = x1;
x2 = x1 + 10;
x3 = x1 + 20;
lost = true;
fill(255, 76, 76);
text("Press R to restart", 85, 330);
}
}
if (aa == true) {
fill(112, 166, 255);
text("You Won.", 200, 200);
fill(255, 76, 76);
text("Press R to restart", 85, 330);
}
if (ab == true) {
fill(112, 166, 255);
text("You Clicked to early.", 120, 200);
fill(255, 76, 76);
text("Press R to restart", 85, 330);
}
^^抽奖功能^^ vv设置功能vv
function setup() {
createCanvas(400, 400);
r = random(900, 4000);
x = 100 - 20;
y = 200 - 20;
x1 = r
y1 = 150;
x2 = x1 + 10;
y2 = 180;
x3 = x2 + 10;
y3 = 150;
textSize(30);
noStroke();
start = "Click screen to play";
trianglespeed = 0;
lost = false;
playing = false;
win = false;
po = 60;
pi = 100;
input = createInput();
aa = false;
ab = false;
pressed = false;
time = 0;
popo = 0;
}
当我启动它/单击运行 它显示错误
: Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
"%cDid you just try to use p5.js's str() function? If so, you may want to move it into your sketch's setup() function.\n\nFor more details, see: github.com/processing/p5.js/wiki/Frequently-Asked-Questions#why-cant-i-assign-variables-using-p5-functions-and-variables-before-setup"
答案 0 :(得分:2)
我认为您需要在代码的第一行中的“联合”之前添加“ f”。
由于setup函数中的所有变量都是局部变量,因此它们不会在draw函数中注册,从而导致错误。
要解决该错误,请将“ let”放在变量前面,然后在任何函数之外声明变量。