2016-11-02 5 views
0

私は間違いを見つけられないようですが、if文を削除するとうまく動作します。コードは非常に短いので、問題を見つけるのは簡単です。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, 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; 
} 

例外: 捕捉されないでSyntaxErrorを:予期しない識別子

これが失敗した理由
+0

正確なエラーメッセージを含めてください。 – JosephGarrone

+0

未知のSyntaxError:予期しない識別子 – Lauritz

+1

どのようにそのJavaScriptですか? –

答えて

-1

は分からないのですが、あなたは回避策として、これを試すことができます。

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; 
} 
0

私はここでそれを実行する場合、あなたのコードがうまく動作します:http://processingjs.org/tools/processing-helper.html

コードをどのように正確に実行していますか?

Javaモードでプログラミングを行い、次にエクスポートするためにJavaScriptモードに切り替えることを強くお勧めします。 setup()関数が呼び出される前に、あなたがframeRate()background()random()などの呼び出しを持つべきではありません

  • :これは、あなたが持っているすべての小さなエラーを、キャッチします。 setup()の機能の中に移動してください。

  • random()関数はfloatの値を返しますが、変数intに格納しています。 JavaScriptは文句を言うことはありませんが、奇妙な振る舞いを引き起こします。

関連する問題