Uncaught SyntaxError: Unexpected identifier on openprocessing with processing.js

Uncaught SyntaxError: Unexpected identifier on openprocessing with processing.js

有问题的代码是这样的:

void update() {
  int nearbyYou = 0;
  int nearbyWork = 0;
  int nearbyCap = 0;
  int nearbyDead = 0;
  for (int iter = 0; iter < 8; iter = iter + 1) {
    switch nearby[iter] {
      case 0:
        nearbyDead++;
      case 1:
        nearbyYou++;
      case 2:
        nearbyWork++;
      case 3:
        nearbyCap++;
    }
    switch type {
      case 0:
        if (nearbyWork >= 1) {
          type = 1;
        } else {
          type = 0;
        }
      case 1:
        if (nearbyWork >= 1) {
          type = 2;
        } else if (nearbyWork >= 7 || nearbyCap >= 2) {
          type = 3;
        } else {
          type = 0;
        }
      case 2:
        type = 0;
    }
  }
}
}

我在处理文件

中得到一个Uncaught SyntaxError: Unexpected identifier
Uncaught SyntaxError: Unexpected identifier
https://preview.openprocessing.org/assets/js/vendor/processingjsReleases/processing-1.6.6.js?version=7.42, line 885
https://preview.openprocessing.org/assets/js/vendor/processingjsReleases/processing-1.6.6.js?version=7.42, line 21586
https://preview.openprocessing.org/assets/js/vendor/processingjsReleases/processing-1.6.6.js?version=7.42, line 21623
https://preview.openprocessing.org/sketch/preview/?random=0.24172648490425175, line 49
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js, line 2
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js, line 2

我在这里和那里尝试了几件事,但我真的不知道如何解决这个错误。

我不知道 processingJS。但我快速搜索证明 int 是一个有效的关键字。尝试用括号切换。例如:开关(类型){ ... }。

您还引用了 nearby[index] 但看不到数组 nearby 在您的代码中还有变量 type,只能安全地假设两者都在范围内可用(或者它们是?)。

此外,如果您查看控制台上的错误,您可能会看到生成错误的行号。

请随时询问所有必要的代码。