I don't know what I am doing wrong! (class and brackets)

Doing the zoog assignment and we are starting with the class chapters. We are working on our zoog and I can’t figure out what is wrong with my code.
I am a suppperrr beginner. My brain just isn’t processing (ha see what I did there?) this and I need help.

void setup() {
  size(500, 300);
  meich = new Meich(width/2, height/2, 60, 60, 16);
int eyeSize, eyeSize2;
Meich meich;
}

void draw() {
  background(247, 223, 242);
  float factor = constrain(mouseX/10, 0, 5);
  meich.jiggle(factor);
  meich.display();
}

class Meich {
  // Zoog's variables
  float meichX, meichY, meichW, meichH, eyeSize;
}
  // Zoog constructor
 Meich(float tempX, float tempY, float tempW, float tempH, float tempEyeSize) {
    meichX = tempX;
    meichY = tempY;
    meichW = tempW;
    meichH = tempH;
    eyeSize = tempEyeSize;
  }

  // Move Zoog
  void jiggle(float speed) {
    // Change the location of Zoog randomly
    meichX = meichX + random(-1, 1)*speed;
    meichY = meichY + random(-1, 1)*speed;
    // Constrain Zoog to window
    meichX = constrain(meichX, 0, width);
    meichY = constrain(meichY, 0, height);
  }

  // Display Zoog
  void display() {
    // Set ellipses and rects to CENTER mode
    ellipseMode(CENTER);
    rectMode(CENTER);
    // Loop Arms
    for (float i = meichY + 5; i < meichY + meichH; i += 10) {
      stroke(0);
      line(meichX-meichW/3, i, meichX+meichW/3, i);

      // Draw body
      stroke(0);
      fill(2, 242, 218);
      rect(meichX, meichY, meichW/5, meichH*2);
      //head
      stroke(0);
      fill(242, 225, 208);
      ellipse(meichX, meichY-30, meichW, meichH);

      //eyes
      eyeR = random(255);
      eyeG = random(255);
      eyeB = random(255);
      fill(eyeR, eyeG, eyeB);
      ellipse(meichX-meichW/3, meichY-meichH/2, eyeSize, eyeSize*2);
      ellipse(meichX+meichW/3, meichY-meichH/2, eyeSize, eyeSize*2);
      //nose
      fill (242, 194, 177);
      ellipse (meichX, meichY-25, 5, 3);
      // mouth
      fill (242, 2, 2);
      ellipse (meichX, meichY-12, 20, 10);

      //legs
      stroke(150);
      line(meichX-meichW/12, meichY+meichH, meichX-meichW/4, meichY+meichH+10);
      line(meichX+meichW/12, meichY+meichH, meichX+meichW/4, meichY+meichH+10);
    }

Hi and welcome

Here is book for beginners

https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://dl.acm.org/doi/pdf/10.5555/1481360&ved=2ahUKEwi5mMeXoPmBAxUuhP0HHaTrCt0QFnoECB8QAQ&usg=AOvVaw0PzjeQazhLloMRPfWLcm6E

Your code won’t run as posted. The following are a few things that you can do to get started.

  1. Read the guidelines at the top to see how to ask questions. Specifically your code needs to be formatted. Either use the menubar symbols for formatting or copy/paste your code between two sets of three graeve characters.

  2. All of the brackets (also called braces) need to be matched sets, ie {…} one opening bracket and one closing bracket per pair. I had to add a couple of closing brackets at the end to get your code to run.

  3. The Meich class needs a constructor called Meich. You named your constructor Zoog, please rename it to ‘Meich’.

  4. There need to be some variables defined at the top of your program, the following should get you started:

int eyeSize, eyeSize2;
Meich meich;

If you make these changes it should allow your code to run in the Processing editor. Then you can refine and debug your code to get the result that you are looking for.

I am using that book. I actually took most of the code from their zoog to use for mine because I just don’t understand. Their code works, but mine doesn’t. I really just don’t understand this. :cry:

Thank you. I really appreciate your comment. I am so lost. This is a required class for my design degree, and it really feels like learning a foreign language.
I will fix those variables to be defined. Thank you :slight_smile:

Don’t give up. You can do this, and we are here to help you succeed.

Okay, fixed the class name, and I think I fixed the brackets. But now it is giving me the code that meich does not exist. I know this is so basic and I feel so dumb asking, but how do I make the variable meich work? Its been working for weeks, but now that we are requiring the class I just don’t get it. I did the int eyeSize.

Did you define Meich? Should be Meich meich; at the top (or alternatively following the class structure). You can check those brackets by placing your cursor directly behind the closing bracket and then looking up above. The bracket that it thinks it goes with should be highlighted. Did you rename the constructor? Meich class is expecting a constructor called Meich (you had it named ‘Zoog’).

void setup() {
  size(500, 300);
  meich = new Meich(width/2, height/2, 60, 60, 16);
int eyeSize, eyeSize2;
Meich meich;
}

void draw() {
  background(247, 223, 242);
  float factor = constrain(mouseX/10, 0, 5);
  meich.jiggle(factor);
  meich.display();
}

class Meich {
  // Zoog's variables
  float meichX, meichY, meichW, meichH, eyeSize;
}
  // Zoog constructor
 Meich(float tempX, float tempY, float tempW, float tempH, float tempEyeSize) {
    meichX = tempX;
    meichY = tempY;
    meichW = tempW;
    meichH = tempH;
    eyeSize = tempEyeSize;
  }

  // Move Zoog
  void jiggle(float speed) {
    // Change the location of Zoog randomly
    meichX = meichX + random(-1, 1)*speed;
    meichY = meichY + random(-1, 1)*speed;
    // Constrain Zoog to window
    meichX = constrain(meichX, 0, width);
    meichY = constrain(meichY, 0, height);
  }

  // Display Zoog
  void display() {
    // Set ellipses and rects to CENTER mode
    ellipseMode(CENTER);
    rectMode(CENTER);
    // Loop Arms
    for (float i = meichY + 5; i < meichY + meichH; i += 10) {
      stroke(0);
      line(meichX-meichW/3, i, meichX+meichW/3, i);

      // Draw body
      stroke(0);
      fill(2, 242, 218);
      rect(meichX, meichY, meichW/5, meichH*2);
      //head
      stroke(0);
      fill(242, 225, 208);
      ellipse(meichX, meichY-30, meichW, meichH);

      //eyes
      eyeR = random(255);
      eyeG = random(255);
      eyeB = random(255);
      fill(eyeR, eyeG, eyeB);
      ellipse(meichX-meichW/3, meichY-meichH/2, eyeSize, eyeSize*2);
      ellipse(meichX+meichW/3, meichY-meichH/2, eyeSize, eyeSize*2);
      //nose
      fill (242, 194, 177);
      ellipse (meichX, meichY-25, 5, 3);
      // mouth
      fill (242, 2, 2);
      ellipse (meichX, meichY-12, 20, 10);

      //legs
      stroke(150);
      line(meichX-meichW/12, meichY+meichH, meichX-meichW/4, meichY+meichH+10);
      line(meichX+meichW/12, meichY+meichH, meichX+meichW/4, meichY+meichH+10);
    }

You’ve figured out how to format code. Now go back to your original post and edit it and format that code.

Phew, figured that out. As you can see, I am not great at computers :slight_smile: Okay, so I fixed a few of the things, but it pasted the old one, so I am going to edit that. I swear. I really stink at this game. LOL. And I will go in a fix my original question, Thank you.
Also, the error is a syntax error, saying it is an incomplete statement. or extra code near extraneous input.

Just add three graeve characters at the beginning and end of your original code and it will be formatted:

```
// code here

```

Should I have the class be in its own tab? What would I put there? This is an online only class, and even though I have watched all of the Dan Shiffman videos up to our current chapter, it is as clear as mud lol. I get it, until we move to the zoog, and then it all of a sudden looks like a different language.

You may put your class under a Tab; that will reduce the amount of code in your main program, but it would probably be better to get it all working inline before doing that (otherwise you’ll be doing a lot of flipping back and forth to debug it).

The eyesize and Meich variables are called ‘global’ variables. They need to be defined at the very top of your code and outside of setup() so that your entire program can see and use them.

Okay. Thank you Svan. Seriously, I am in tears trying to figure this out, and having a real person to ask question to has been such a blessing. So do you know why there is still an error, (incomplete statement or extra code near extraneous input)?

1 Like

Oh perfect. So before setup?

Repost the source code so that I can see what you currently have. Probably best to leave the original post alone and maybe edit that second code post that you made, so that we can see your progress.

So before setup?

Yes.

Meich meich; 
int eyeSize, eyeSize2;

void setup() {
  size(500, 300);
  meich = new Meich(width/2, height/2, 60, 60, 16);
}

void draw() {
  background(247, 223, 242);
  float factor = constrain(mouseX/10, 0, 5);
  meich.jiggle(factor);
  meich.display();
}

class Meich {
  // Zoog's variables
  float meichX, meichY, meichW, meichH, eyeSize;
}
  // Zoog constructor
 Meich(float tempX, float tempY, float tempW, float tempH, float tempEyeSize) {
    meichX = tempX;
    meichY = tempY;
    meichW = tempW;
    meichH = tempH;
    eyeSize = tempEyeSize;
  }

  // Move Zoog
  void jiggle(float speed) {
    // Change the location of Zoog randomly
    meichX = meichX + random(-1, 1)*speed;
    meichY = meichY + random(-1, 1)*speed;
    // Constrain Zoog to window
    meichX = constrain(meichX, 0, width);
    meichY = constrain(meichY, 0, height);
  }

  // Display Zoog
  void display() {
    // Set ellipses and rects to CENTER mode
    ellipseMode(CENTER);
    rectMode(CENTER);
    // Loop Arms
    for (float i = meichY + 5; i < meichY + meichH; i += 10) {
      stroke(0);
      line(meichX-meichW/3, i, meichX+meichW/3, i);

      // Draw body
      stroke(0);
      fill(2, 242, 218);
      rect(meichX, meichY, meichW/5, meichH*2);
      //head
      stroke(0);
      fill(242, 225, 208);
      ellipse(meichX, meichY-30, meichW, meichH);

      //eyes
      eyeR = random(255);
      eyeG = random(255);
      eyeB = random(255);
      fill(eyeR, eyeG, eyeB);
      ellipse(meichX-meichW/3, meichY-meichH/2, eyeSize, eyeSize*2);
      ellipse(meichX+meichW/3, meichY-meichH/2, eyeSize, eyeSize*2);
      //nose
      fill (242, 194, 177);
      ellipse (meichX, meichY-25, 5, 3);
      // mouth
      fill (242, 2, 2);
      ellipse (meichX, meichY-12, 20, 10);

      //legs
      stroke(150);
      line(meichX-meichW/12, meichY+meichH, meichX-meichW/4, meichY+meichH+10);
      line(meichX+meichW/12, meichY+meichH, meichX+meichW/4, meichY+meichH+10);
    }