Enums in OpenProcessing

edited July 2017 in JavaScript Mode

I made a game in processing and it worked just fine. I tried to upload it to OpenProcessing and then it sent me this error when I tried to run the game: "Unexpected reserved word" So I tried to add the pieces of code one by one to see which one causes this error and then I reached this enum:

public enum TileType {
  EMPTY,
  APPLE,
  SNAKE;
}

I do not understand what is wrong with it, it works just fine on my computer. I can replace the enums with strings or something else but I prefer to not do that because: a. Enums are more efficient b. I will need to change many things and I'm lazy

Answers

  • edited July 2017 Answer ✓
    • enum was added very recently in Processing 3. 8-X
    • And Pjs' transpiler can't convert enum to JS unfortunately. :(
    • interface doesn't seem to work either. :-&
    • Next best thing is static abstract class then: :ar!

    /** 
     * Enum Class (v1.0)
     * GoToLoop (2017/Jul/12)
     *
     * Forum.Processing.org/two/discussion/23409/
     * enums-in-openprocessing#Item_1
     */
    
    static abstract class TileType {
      static final int EMPTY = 0;
      static final int APPLE = 1;
      static final int SNAKE = 2;
    }
    
    void setup() {
      int tile = TileType.SNAKE;
      println(tile); // 2
      exit();
    }
    
Sign In or Register to comment.