Search code examples
javascriptprocessingprocessing.js

Uncaught SyntaxError: Unexpected identifier on openprocessing with processing.js


The code in question is this:

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

And I get an Uncaught SyntaxError: Unexpected identifier in the processing file

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

I've tried a couple things here and there but I really don't know how to adress this error.


Solution

  • i don't know about processingJS. but i quick search proved int is a valid keyword. try switch with paranthesis. eg: switch (type) { ... }.

    Also you are referencing nearby[index] but can't see an array nearby in your code also the variable type, which can only be safely assume both are available within the scope(or are they?).

    Also, if you look at the error on the console, you can probably see the line number where the error has been generated.

    please always ask with all the necessary code.