Newby question? Found one too many { characters without a } to match it

edited October 2013 in Questions about Code

Hi Folks, I'm a new processing user, and I'm learning with the book "learning processing" by danniel shiffman. There is a simple game example in page 186 based in a catcher which catch drops falling from top of screen. It has 3 classes and a main program. I have copied literally the code of the example but I get this message over and over again, and I'm not capable to find the bug... some suggestion? I became to be very frustrated. The sketch is separated in 4 tabs (raindrops_game,Catcher,Drop and Timer). Mac based and processing 2.0.3.

Thanks in advance.

Catcher catcher;
Timer timer;
Drop[] drops;

int totalDrops=0;

void setup(){
  size(400,400);
  smooth();
  catcher=new Catcher(32);
  drops=new Drop[1000];
  timer=new Timer(300); //define un objeto timer que equivale a un intervalo. 

  timer.start();//establece una marca inicial de tiempo.
}


void draw(){
  background(255);
  catcher.setLocation(mouseX,mouseY);
  catcher.display();

  if (timer.isFinished()){
    drops[totalDrops]=new Drop();
    totalDrops++;
  //si nosotros llegamos al final del array
  if (totalDrops>=drops.length){
    totalDrops = 0;   
 }
 timer.start();
}


 //mueve y dibuja las gotas
 for (int i=0;i<totalDrops;i++) {
   drops[i].move();
   drops[i].display();
   if(catcher.intersect(drops[i])){
     drops[i].caught();
   }  
  }
}


class Catcher{
 float r; //radius
 color col;
 float x,y; //location

  Catcher(float tempR){
    r=tempR;
    col=color(50,10,10,150);
    x=0;
    y=0;
 }

void setLocation(float tempX, float tempY){
  x=tempX;
  y=tempY;
}

void display(){
  stroke(0);
  fill(col);
  ellipse(x,y,r*2,r*2);
  }

  boolean intersect(Drop d){
    float distance=dist(x,y,d.x,d.y);//calculate distance
    if (distance < r+d.r){//compare distance to sum of radio.
      return true;
    }else{
      return false;
    }
  }


class Drop {

  float x,y;
  float speed;
  color c;
  float r;

Drop(){

  r=8; //todas las gotas tienen el mismo tamaño
  x=random(width);//empieza con una localizacion en el eje X aleatoria
  y=-r*4;//empieza una pequeña gota en el top de la ventana
  speed=random(1,5);//adquiere una velocidad aleatoria
  c=color(50,100,150);//color
}

//mueve la gota hacia abajo
void move(){
  y+=speed;// se incrementa la posición en el eje y por la velocidad.
}

//Comprueba si las gotas llegan al suelo

boolean reachedBottom(){
 if (y>height+r*4){
    return true;
  }else{
    return false;
  }
}
//dibujamos la gota
void display(){
 fill(c);
 noStroke();
 for(int i=2;i < r;i++){
 ellipse(x,y+i*4,i*2,i*2); 
 }
}

void caught(){
  speed=0;
  y=-1000;
 }
 }


class Timer {

  int savedTime;
  int totalTime;

  Timer (int tempTotalTime) {
    totalTime=tempTotalTime;
  }

  void start() {
    savedTime=millis();
  }

  boolean isFinished() {
    int passedTime=millis()-savedTime;
    if (passedTime>totalTime) {
      return true;
    }
    else {
      return false;
    }
  }
 }
Tagged:

Answers

  • Could you at the very least use CTRT+T in Processing's IDE.
    And then when pasting the code here, select it and press C button?

  • edited October 2013

    Ups, no I didn't know anything about C button, sorry... I have tried CTRL+T but the bug exists yet... I'm really confused... Thanks for the help in advance!

    Catcher catcher;
    Timer timer;
    Drop[] drops;
    
    int totalDrops=0;
    
    void setup(){
      size(400,400);
      smooth();
      catcher=new Catcher(32);
      drops=new Drop[1000];
      timer=new Timer(300); //define un objeto timer que equivale a un intervalo. 
    
      timer.start();//establece una marca inicial de tiempo.
    }
    
    
    void draw(){
      background(255);
      catcher.setLocation(mouseX,mouseY);
      catcher.display();
    
      if (timer.isFinished()){
        drops[totalDrops]=new Drop();
        totalDrops++;
      //si nosotros llegamos al final del array
      if (totalDrops>=drops.length){
        totalDrops = 0;   
     }
     timer.start();
    }
    
    
     //mueve y dibuja las gotas
     for (int i=0;i<totalDrops;i++) {
       drops[i].move();
       drops[i].display();
       if(catcher.intersect(drops[i])){
         drops[i].caught();
       }  
      }
    }
    
    class Catcher{
     float r; //radius
     color col;
     float x,y; //location
    
      Catcher(float tempR){
        r=tempR;
        col=color(50,10,10,150);
        x=0;
        y=0;
     }
    
    void setLocation(float tempX, float tempY){
      x=tempX;
      y=tempY;
    }
    
    void display(){
      stroke(0);
      fill(col);
      ellipse(x,y,r*2,r*2);
      }
    
      boolean intersect(Drop d){
        float distance=dist(x,y,d.x,d.y);//calculate distance
        if (distance < r+d.r){//compare distance to sum of radio.
          return true;
        }else{
          return false;
        }
      }
    
    class Drop {
    
      float x,y;
      float speed;
      color c;
      float r;
    
    Drop(){
    
      r=8; //todas las gotas tienen el mismo tamaño
      x=random(width);//empieza con una localizacion en el eje X aleatoria
      y=-r*4;//empieza una pequeña gota en el top de la ventana
      speed=random(1,5);//adquiere una velocidad aleatoria
      c=color(50,100,150);//color
    }
    
    //mueve la gota hacia abajo
    void move(){
      y+=speed;// se incrementa la posición en el eje y por la velocidad.
    }
    
    //Comprueba si las gotas llegan al suelo
    
    boolean reachedBottom(){
     if (y>height+r*4){
        return true;
      }else{
        return false;
      }
    }
    //dibujamos la gota
    void display(){
     fill(c);
     noStroke();
     for(int i=2;i < r;i++){
     ellipse(x,y+i*4,i*2,i*2); 
     }
    }
    
    void caught(){
      speed=0;
      y=-1000;
     }
     }
    
    
    class Timer {
    
      int savedTime;
      int totalTime;
    
      Timer (int tempTotalTime) {
        totalTime=tempTotalTime;
      }
    
      void start() {
        savedTime=millis();
      }
    
      boolean isFinished() {
        int passedTime=millis()-savedTime;
        if (passedTime>totalTime) {
          return true;
        }
        else {
          return false;
        }
      }
     }
    
  • edited October 2013 Answer ✓

    here...

    a } was missing after the 2nd class

    after using ctrl-t you can check the indent:
    like void or class a closing } (for a function or a class but not for for-loop or if of course) must be at indent 0 (or 1) if that is not the case, a closing } must be missing before

    Catcher catcher;
    Timer timer;
    Drop[] drops;
    
    int totalDrops=0;
    
    void setup() {
      size(400, 400);
      smooth();
      catcher=new Catcher(32);
      drops=new Drop[1000];
      timer=new Timer(300); //define un objeto timer que equivale a un intervalo. 
    
      timer.start();//establece una marca inicial de tiempo.
      //
    } // func 
    
    
    void draw() {
      background(255);
      catcher.setLocation(mouseX, mouseY);
      catcher.display();
    
      if (timer.isFinished()) {
        drops[totalDrops]=new Drop();
        totalDrops++;
        //si nosotros llegamos al final del array
        if (totalDrops>=drops.length) {
          totalDrops = 0;
        }
        timer.start();
      }
    
    
      //mueve y dibuja las gotas
      for (int i=0;i<totalDrops;i++) {
        drops[i].move();
        drops[i].display();
        if (catcher.intersect(drops[i])) {
          drops[i].caught();
        }
      }
    } // func 
    
    // =======================================================
    
    class Catcher {
      float r; //radius
      color col;
      float x, y; //location
    
      Catcher(float tempR) {
        r=tempR;
        col=color(50, 10, 10, 150);
        x=0;
        y=0;
      }
    
      void setLocation(float tempX, float tempY) {
        x=tempX;
        y=tempY;
      }
    
      void display() {
        stroke(0);
        fill(col);
        ellipse(x, y, r*2, r*2);
      }
    
      boolean intersect(Drop d) {
        float distance=dist(x, y, d.x, d.y);//calculate distance
        if (distance < r+d.r) {//compare distance to sum of radio.
          return true;
        }
        else {
          return false;
        }
      }
    } // class 
    
    // =======================================================
    
    class Drop {
    
      float x, y;
      float speed;
      color c;
      float r;
    
      Drop() {
    
        r=8; //todas las gotas tienen el mismo tamaño
        x=random(width);//empieza con una localizacion en el eje X aleatoria
        y=-r*4;//empieza una pequeña gota en el top de la ventana
        speed=random(1, 5);//adquiere una velocidad aleatoria
        c=color(50, 100, 150);//color
      }
    
      //mueve la gota hacia abajo
      void move() {
        y+=speed;// se incrementa la posición en el eje y por la velocidad.
      }
    
      //Comprueba si las gotas llegan al suelo
    
      boolean reachedBottom() {
        if (y>height+r*4) {
          return true;
        }
        else {
          return false;
        }
      }
      //dibujamos la gota
      void display() {
        fill(c);
        noStroke();
        for (int i=2;i < r;i++) {
          ellipse(x, y+i*4, i*2, i*2);
        }
      }
    
      void caught() {
        speed=0;
        y=-1000;
      }
    } // class 
    
    // =======================================================
    
    class Timer {
    
      int savedTime;
      int totalTime;
    
      Timer (int tempTotalTime) {
        totalTime=tempTotalTime;
      }
    
      void start() {
        savedTime=millis();
      }
    
      boolean isFinished() {
        int passedTime=millis()-savedTime;
        if (passedTime>totalTime) {
          return true;
        }
        else {
          return false;
        }
      }
    } // class
    
    // 
    
  • Many thanks Chrisir!!! it's working fine!!! I was getting crazy! Thanks for your comments in the code,are very helpfull!!)

  • you are welcome, thank you for your feedback!

Sign In or Register to comment.