1

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.

5
  • the line 885 code is from the processing.js itself, nothing to do with me. And yes, I commented the whole void update() to see if other int x worked and yes they did Commented Jan 21, 2020 at 17:30
  • See https://preview.openprocessing.org/sketch/preview/?random=0.24172648490425175, line 49 so your error should be ocurring on line 49 Commented Jan 21, 2020 at 17:37
  • The example is not complete and verifiable. What is the last } for? Commented Jan 21, 2020 at 17:37
  • This probably isn't the solution to your problem, but switch statements' cases need to break. See prosssesing-js::switch Commented Jan 21, 2020 at 17:40
  • The last } is a mistake, the line 49 is the for loop Commented Jan 21, 2020 at 17:41

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.