Missing curly bracket???

Okay, so I'm trying to make a game. This is what I have so far:

long lT = 0;
boolean againstWall = false;
char wallPoint = 'n';

void setup() {
  size(1000,500);
  lT = millis();
}

float playermxpos = 5;
float playermypos = 5;
color wall1 = #CD5000;

void draw() {
  background(51);
  float player1xpos = playermxpos + 5;
  float player1ypos = playermypos + 3;
  float player2xpos = playermxpos + 3;
  float player2ypos = playermypos + 5;
  //<playersetup>
  if (keyPressed) {
    if (key == CODED) {
    if (millis() - lT >= 50) {
    int code = keyCode;
    switch (code) {
      case UP:
        playermypos = playermypos - 10;
        break;
      case DOWN:
        playermypos = playermypos + 10;
        break;
      case LEFT:
        playermxpos = playermxpos -10;
        break;
      case RIGHT:
        playermxpos = playermxpos + 10;
        break;
      default:
        break;
    }
  }
  lT = millis();
  }}
  noStroke();
  fill(255, 201, 0);
  rect(player2xpos, player2ypos, 10, 6);
  rect(player1xpos, player1ypos, 6, 10);
  //</playersetup>
  //<wallsetup>
  class Wall {
    float xpos, ypos, col;
    Wall (float xp, float yp, float c) {
      xpos = xp;
      ypos = yp;
      col = c;
    }

    switch (col) { //<----------------------------------extra curly brace is right here!
      case 1:
        fill(wall1);
        break;
      default:
        fill(wall1);
        break;
    }
    rect(xpos, ypos, 10, 10);

    if (ypos == playermypos) {
      for (int x = -10; x < 11; x = x + 20) {
        if (xpos + x == playermxpos) {
          againstWall = true;
          if (x == -10) {
            wallPoint = 'w';
          } else {
            wallPoint = 'e';
          }
        }
      }
    }
    if (xpos == playermxpos) {
      for (int y = -10; y < 11; y = y + 20) {
        if (ypos + y == playermypos) {
          againstWall = true;
          if (y == -10) {
            wallPoint = 'n';
          } else {
            wallPoint = 's';
          }
        }
      }
    }
  }
  Wall w001 = new Wall(
}

However, at this point when I try to run it, it says that there is a missing curly brace (found one too many { characters without a } to match it) right here:

  class Wall {
    float xpos, ypos, col;
    Wall (float xp, float yp, float c) {
      xpos = xp;
      ypos = yp;
      col = c;
    }

    switch (col) { //right here
      case 1:
        fill(wall1);
        break;
      default:
        fill(wall1);
        break;
    }
    rect(xpos, ypos, 10, 10);

This isn't the first time Processing has found an extra { that isn't actually there, and it's getting rather annoying. Please help! I really like Processing (much better than having three docs just for one page (html, css, jquery)) but if it keeps doing this I don't know what to do!

Thanks, Me

Answers

  • edited March 2014

    You have 29 left parenthesis and just 28 right parenthesis (line 93). Plus it seems you are trying to declare a class inside your draw() function in which you've placed a switch() block, a rect() call and two if() blocks without a wrapping function or constructor block, which is most probably the cause of your problem. Is this your actual code?

  • All lines from #58 up to #93 are methodless, orphans!
    You gotta place them inside some method scope!

  • Okay, I fixed that, but now it says "the type game.WALL must implement the inherited abstract method game.Wall" I, have no idea what this means.

    long lT = 0;
    boolean againstWall = false;
    boolean wallPointN = false;
    boolean wallPointE = false;
    boolean wallPointS = false;
    boolean wallPointW = false;
    
    void setup() {
      size(1000,500);
      lT = millis();
    }
    
    float playermxpos = 5;
    float playermypos = 5;
    
      interface Wall {
        void wallSetup(int xp, int yp, int c);
      }
      class WALL implements Wall {
    
        int xpos = 0;
        int ypos = 0;
        int wc = 0;
    
        void Wall (int xp, int yp, int c) {
          xpos = xp;
          ypos = yp;
          wc = c;
    
    switch(wc) {
      case 1:
        fill(wall1);
        break;
      default:
        fill(wall1);
        break;
    }
    
        rect(xpos, ypos, 10, 10);
    
        if (ypos == playermypos) {
          for (int x = -10; x < 11; x = x + 20) {
            if (xpos + x == playermxpos) {
              againstWall = true;
              if (x == -10) {
                wallPointW = true;
              } else {
                wallPointE = true;
              }
            }
          }
        }
        if (xpos == playermxpos) {
          for (int y = -10; y < 11; y = y + 20) {
            if (ypos + y == playermypos) {
              againstWall = true;
              if (y == -10) {
                wallPointN = true;
              } else {
                wallPointS = true;
              }
            }
          }
        }}
      }
    
    
    void draw() {
      background(51);
      float player1xpos = playermxpos + 5;
      float player1ypos = playermypos + 2+1;
      float player2xpos = playermxpos + 2+1;
      float player2ypos = playermypos + 5;
      //<playersetup>
      if (keyPressed) {
        if (key == CODED) {
        if (millis() - lT >= 50) {
        int code = keyCode;
        switch (code) {
          case UP:
            if (!wallPointN) {
            playermypos = playermypos - 10;
            }
            break;
          case DOWN:
            if (!wallPointS) {
            playermypos = playermypos + 10;
            }
            break;
          case LEFT:
            if (!wallPointW) {
            playermxpos = playermxpos -10;
            }
            break;
          case RIGHT:
            if (!wallPointE) {
            playermxpos = playermxpos + 10;
            }
            break;
          default:
            break;
        }
      }
      lT = millis();
      }}
      noStroke();
      fill(255, 201, 0);
      rect(player2xpos, player2ypos, 10, 6);
      rect(player1xpos, player1ypos, 6, 10);
      //</playersetup>
      //<wallsetup>
      color wall1 = #CD5000;
    
      Wall w001 = new Wall(0,0,1);
    }
    
  • edited April 2014

    I have no idea what this means.

    You've defined an interface and doesn't know what it's for??? ~:>
    Any class which implements an interface must contain all methods listed inside that!

    Your interface Wall has the following abstract method wallSetup().
    Since class WALL implements Wall interface, it must also contain an implemented wallSetup() method! #:-S

    P.S.: By convention, neither classes nor interfaces use all-caps names! :-w

  • Oh. I thought I had already done that. So I fixed it, but now it says "the constructor game.Wall(int,int,int) is undefined". More help?

      interface WallUI {
        void wallSetup(int xp, int yp, int c);
      }
      class Wall implements WallUI {
    
        int xpos = 0;
        int ypos = 0;
        int wc = 0;
    
    
        void wallSetup (int xp, int yp, int c) {
          xpos = xp;
          ypos = yp;
          wc = c;
        }
        void Wall (int xp, int yp, int c) {
    
    
    
        switch(wc) {
          case 1:
            fill(wall1);
            break;
          default:
            fill(wall1);
            break;
        }
    
        rect(xpos, ypos, 10, 10);
    
        if (ypos == playermypos) {
          for (int x = -10; x < 11; x = x + 20) {
            if (xpos + x == playermxpos) {
              againstWall = true;
              if (x == -10) {
                wallPointW = true;
              } else {
                wallPointE = true;
              }
            }
          }
        }
        if (xpos == playermxpos) {
          for (int y = -10; y < 11; y = y + 20) {
            if (ypos + y == playermypos) {
              againstWall = true;
              if (y == -10) {
                wallPointN = true;
              } else {
                wallPointS = true;
              }
            }
          }
        }}
      }
    
    void draw() {
    Wall w001 = new Wall(0,0,1);
    }
    

    P.S. From now on I'm going to be adding the code that has the problem, and nothing else, because I don't think that going through the entire code is very time-saving. If you want the entire code at any point, tell me and I will do so soon. Thanks.

  • this is your constructor

    void Wall (int xp, int yp, int c) {
          xpos = xp;
          ypos = yp;
          wc = c;
    

    but the } is missing

    instead it goes on with

    switch(wc) {
          case 1:
            fill(wall1);
            break;
          default:
            fill(wall1);
            break;
        }
    
        rect(xpos, ypos, 10, 10);
    

    there must be

    void display() { 
    

    or so before switch !

    Did you wrote this or copied it ?

  • no wait

     void wallSetup (int xp, int yp, int c) {
          xpos = xp;
          ypos = yp;
          wc = c;
        }
    

    this is your constructor?

    must be the same name as the class and without void

      Wall (int xp, int yp, int c) {
          xpos = xp;
          ypos = yp;
          wc = c;
        }
    
  • directly afterwards I read

    void Wall (int xp, int yp, int c) {

    bad.

    Better give it another name like wallDisplay or display

  • edited April 2014

    You have:

    void Wall (int xp, int yp, int c)

    A constructor has no type. It should be:

    Wall (int xp, int yp, int c)

Sign In or Register to comment.