Javascript if()处的processing.js意外标识符

Javascript if()处的processing.js意外标识符,javascript,identifier,processing.js,Javascript,Identifier,Processing.js,我似乎找不到错误,但当我删除if语句时,它运行良好。代码很短,因此应该很容易找到问题 int zw1; int zw2; int px = 100; int py = 100; int ppx = px + random(-20, 20); int ppy = py + random(-20, 20); int cx; int cy; int xrand = 50; int yrand = 50; int opacity = 49; frameRate(30); background(74, 7

我似乎找不到错误,但当我删除if语句时,它运行良好。代码很短,因此应该很容易找到问题

int zw1;
int zw2;
int px = 100;
int py = 100;
int ppx = px + random(-20, 20);
int ppy = py + random(-20, 20);
int cx;
int cy;
int xrand = 50;
int yrand = 50;
int opacity = 49;
frameRate(30);
background(74, 71, 74);
int timetoclear = 0;

int x0 = 0;
int y0 = 0;
void setup() {
    size(400, 400);

}
void draw() {

    cx = px + random(-xrand, xrand);
    cy = py + random(-xrand, xrand);

    // fill(74, 72, 74,5);
    // rect(-10,-10,1000,1000);

    //cx = mouseX;
    //cy = mouseY;  
    if (cx <= 0) {
        cx = 0;
    }
    if (cx >= 400) {
        cx = 400;
    }
    if (cy <= 0) {
        cy = 0;
    }
    if (cy >= 640) {
        cy = 640;
    }

    stroke(30 + random(-100, 100), 195 + random(-100, 100), 201, 60);

    fill(30 + random(-100, 100), 195 + random(-100, 100), 201, 50);

    triangle(ppx, ppy, px, py, cx, cy);

    ppx = px;
    ppy = py;
    px = cx;
    py = cy;
}
intzw1;
int-zw2;
int-px=100;
int-py=100;
int-ppx=px+随机(-20,20);
int-ppy=py+random(-20,20);
int-cx;
int cy;
int xrand=50;
int yrand=50;
int不透明度=49;
帧率(30);
背景(74,71,74);
int-timetoclear=0;
int x0=0;
int y0=0;
无效设置(){
尺寸(400400);
}
作废提款(){
cx=px+随机(-xrand,xrand);
cy=py+random(-xrand,xrand);
//填充(74,72,74,5);
//rect(-10,-1010001000);
//cx=鼠标;
//cy=老鼠;
如果(cx=400){
cx=400;
}
如果(cy=640){
cy=640;
}
笔划(30+随机(-100100)、195+随机(-100100)、201、60);
填充(30+随机(-100100)、195+随机(-100100)、201、50);
三角形(ppx,ppy,px,py,cx,cy);
ppx=px;
ppy=py;
px=cx;
py=cy;
}
抛出:
未捕获的语法错误:意外标识符不知道为什么失败,但您可以尝试以下解决方法:

cx = Math.max(0, Math.min(400, cx));
cy = Math.max(0, Math.min(640, cy));
而不是

if (cx <= 0) {
    cx = 0;
}
if (cx >= 400) {
    cx = 400;
}
if (cy <= 0) {
    cy = 0;
}
if (cy >= 640) {
    cy = 640;
}
if(cx=400){
cx=400;
}
如果(cy=640){
cy=640;
}

如果我在此处运行代码,您的代码对我来说运行良好:

你到底是如何运行你的代码的

我强烈建议在Java模式下编程,然后切换到JavaScript模式仅用于导出。这将捕获您所有的小错误,例如:

  • 在调用
    setup()
    函数之前,不应该调用
    frameRate()
    background()
    random()
    。将这些移动到
    setup()
    函数中

  • random()
    函数返回一个
    float
    值,但将其存储在
    int
    变量中。JavaScript不会抱怨,但会导致奇怪的行为


请包含准确的错误消息。未捕获的语法错误:意外的标识符JavaScript是什么?这不是全部错误,它还会给您一个行号和/或列。是否
帧速率
背景
应该在
设置
函数中?