Help, code expecting EOF, found '}'

int money;
PImage pic1;
PImage pic2;

int rx1 = 250;
int ry1 = 200;
int rwidth1 = 280;
int rheight1 = 140;

int rx2 = 600;
int ry2 = 600;
int rwidth2 = 780;
int rheight2 = 780;

void setup() {

size(800, 600);

money = 0;

pic1 = loadImage(“foto_1.png”);
pic2 = loadImage(“foto_2.png”);

noStroke();
}
void mousePressed() {
if (rx1 <= mouseX && mouseX <= rx1 + rwidth1 &&
ry1 <= mouseY && mouseY <= ry1 + rheight1) {
money = money + 1;
}
{
if (rx2 <= mouseX && mouseX <= rx2 + rwidth2 &&
ry2 <= mouseY && mouseY <= ry2 + rheight2);
money >=10 = money - 10;
{
fill(100, 0, 0);
rect(600, 200, 780, 780);
}
}
}
} e{lse fill(230);
rect(600, 200, 780, 780);

}
void draw() {
background(200);
println(money);
textSize(32);
fill(0);
image(pic1, 100, 15);
pic1.resize(0, 80);
image(pic2, 250, 200);
text(money, 50, 60);
}

Check your mousepressed function at first glance you have a typo at the last else statement.

@paulgoux
i fixed it but yet there is expecting EOF, found ‘else’

int money;
PImage pic1;
PImage pic2;

int rx1 = 250;
int ry1 = 200;
int rwidth1 = 280;
int rheight1 = 140;

int rx2 = 600;
int ry2 = 600;
int rwidth2 = 780;
int rheight2 = 780;

void setup() {

size(800, 600);

money = 0;

pic1 = loadImage(“foto_1.png”);
pic2 = loadImage(“foto_2.png”);

noStroke();
}
void mousePressed() {
if (rx1 <= mouseX && mouseX <= rx1 + rwidth1 &&
ry1 <= mouseY && mouseY <= ry1 + rheight1) {
money = money + 1;
}
{
if (rx2 <= mouseX && mouseX <= rx2 + rwidth2 &&
ry2 <= mouseY && mouseY <= ry2 + rheight2);
money >=10 = money - 10;
{
fill(100, 0, 0);
rect(600, 200, 780, 780);
}
}
}
else fill(230);
rect(600, 200, 780, 780);

}
void draw() {
background(200);
println(money);
textSize(32);
fill(0);
image(pic1, 100, 15);
pic1.resize(0, 80);
image(pic2, 250, 200);
text(money, 50, 60);
}

This is how your mousepressed should look. Also remember to format your code.

void mousePressed() {
if (rx1 <= mouseX && mouseX <= rx1 + rwidth1 &&
ry1 <= mouseY && mouseY <= ry1 + rheight1) {
money = money + 1;

}
else if (rx2 <= mouseX && mouseX <= rx2 + rwidth2 &&
ry2 <= mouseY && mouseY <= ry2 + rheight2){
money >=10 = money - 10;

fill(100, 0, 0);
rect(600, 200, 780, 780);
}
else{ fill(230);
rect(600, 200, 780, 780);

}
}

1 Like

@paulgoux
hey but yet there is ,unexoected token: void"

and i cant format my code.

int money;
int owned1;

PImage pic3;
PImage pic1;
PImage pic2;

int rx1 = 250;
int ry1 = 200;
int rwidth1 = 280;
int rheight1 = 140;

int rx2 = 600;
int ry2 = 75;
int rwidth2 = 800;
int rheight2 = 125;

void setup() {

  size(800, 600);

  money = 0;
  owned1 = 0;

  pic1 = loadImage(“foto_1.png”);
  pic2 = loadImage(“foto_2.png”);
  pic3 = loadImage(“foto_3.png”);

  noStroke();
}
void mousePressed() {
  if (rx1 <= mouseX && mouseX <= rx1 + rwidth1 &&
    ry1 <= mouseY && mouseY <= ry1 + rheight1) {
    money = money + 1;
  } else if (rx2 <= mouseX && mouseX <= rx2 + rwidth2 &&
    ry2 <= mouseY && mouseY <= ry2 + rheight2) {
    money >=10 = money - 10;

    }
      void draw() {
      background(200);
      println(money);
      textSize(32);
      fill(0);

      image(pic1, 100, 15);

      pic1.resize(0, 80);
      image(pic2, 250, 200);
      pic3.resize(0, 80);
      image(pic3, 650, 100);

      text(money, 50, 60);
      text(owned1, 650, 120);
    }

To format code press CTRL + SHIFT + C.

youve made a change to the mousepressed function i posted though.

int money;
int owned1;
PImage pic3;
PImage pic1;
PImage pic2;
int rx1 = 250;
int ry1 = 200;
int rwidth1 = 280;
int rheight1 = 140;
int rx2 = 600;
int ry2 = 75;
int rwidth2 = 800;
int rheight2 = 125;

void setup() {
  size(800, 600);
  money = 0;
  owned1 = 0;
  pic1 = loadImage("foto_1.png");
  pic2 = loadImage("foto_2.png");
  pic3 = loadImage("foto_3.png");
  noStroke();
}

void mousePressed() {
  if (rx1 <= mouseX && mouseX <= rx1 + rwidth1 && ry1 <= mouseY && mouseY <= ry1 + rheight1) {
    money = money + 1;
  } else if (rx2 <= mouseX && mouseX <= rx2 + rwidth2 && ry2 <= mouseY && mouseY <= ry2 + rheight2) {
    money = money - 10;
  }
}

void draw() {
  background(200);
  println(money);
  textSize(32);
  fill(0);
  image(pic1, 100, 15);
  pic1.resize(0, 80);
  image(pic2, 250, 200);
  pic3.resize(0, 80);
  image(pic3, 650, 100);
  text(money, 50, 60);
  text(owned1, 650, 120);
}