# How I can do score

**URL:** <https://discourse.processing.org/t/how-i-can-do-score/3223>\
**Category:** Coding Questions\
**Created:** [September 3, 2018, 10:16am UTC](https://discourse.processing.org/t/how-i-can-do-score/3223 "2018-09-03T10:16:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pedro](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pedro](https://discourse.processing.org/u/Pedro)\
**Post date:** [September 3, 2018, 10:16am UTC](https://discourse.processing.org/t/how-i-can-do-score/3223/1 "2018-09-03T10:16:20Z")

</div>

Hello, I’m doing a game and I’m new to Processing, I’ve done this,I’ve been looking for videos, in forums and nothing, I’m having problems in the score, every time I give it where it has to add +1, it adds much more.

```auto
PImage pentagon;
PImage triangle;
PImage sis;
PImage cinc;
PImage quatre;
PImage tres;
PImage rectangle;
int state; 
int points;
boolean pCount = true;
void setup() {
  size(400, 600);
  background(255);
  quatre = loadImage("RECTAANGULO.png");
  tres = loadImage("TRIAANGULO.png");
  rectangle = loadImage("RECTANGLE.png");
  sis = loadImage("HEXAAGONO.png");
  cinc = loadImage("PENTAAGONO.png");
  triangle = loadImage("TRIÀNGLE.png");
  pentagon = loadImage("PENTÀGON.png");
  } 
  
void draw(){
    fill(0);
   textSize(20);
   text("puntuacion:" + points , 20, 550);
   
  if (state == 0) {
   image(rectangle,30,100);
   image(tres,200,220);
   image(quatre,0,220);
   if((mousePressed)&&(mouseX > 20 && mouseX < 190) && (mouseY > 150 && mouseY < 300)){
     ++points;
  }
  }
  if (state == 1) {
   image(pentagon,50,100);
   image(cinc,200,220);
   image(sis, 0, 220);
   if((mousePressed)&&(mouseX > 20 && mouseX < 190) && (mouseY > 150 && mouseY < 300)){
     ++points;
  }
  }
  if (state == 2) {
   image(triangle,30,100);
   image(tres,200,220);
   image(cinc,0,220);
   if((mousePressed)&&(mouseX > 20 && mouseX < 190) && (mouseY > 150 && mouseY < 300)){
     ++points;
  }
  
  }
   if (state == 3) {
   image(rectangle,30,100);
   image(sis,200,220);
   image(quatre,0,220);
   if((mousePressed)&&(mouseX > 20 && mouseX < 190) && (mouseY > 150 && mouseY < 300)){
     ++points;
  }
   }
   
}

void mouseClicked() {
  state++;
  if(state == 4){
    state = 0;
  }
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [September 3, 2018, 10:43am UTC](https://discourse.processing.org/t/how-i-can-do-score/3223/2 "2018-09-03T10:43:27Z")

</div>

Compare this code:

```auto
int counter;

void setup(){
  size(400,400);
}

void draw(){
  background(0);
  if(mousePressed){
    counter++;
  }
  fill(255);
  text( counter, 20, 20);
}

```

To this code:

```auto
int counter;

void setup() {
  size(400, 400);
}

void draw() {
  background(0);
  fill(255);
  text( counter, 20, 20);
}

void mousePressed() {
  counter++;
}

```

See the difference? By using the `mousePressed` boolean in a conditional statement in `draw()` you get a condition that might be true for several iterations of `draw()`. That is, one click might span several frames of drawing.

But if you use the `mousePressed()` function, then this function only runs once per click. Thus code inside it only executes once per click.

---

<div class="post-metadata">

**Author:** ![Pedro](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pedro](https://discourse.processing.org/u/Pedro)\
**Post date:** [September 3, 2018, 11:15am UTC](https://discourse.processing.org/t/how-i-can-do-score/3223/3 "2018-09-03T11:15:15Z")

</div>

THANK YOU!!. I got it, but when I got the points every time, the numbers are put on top of each other.  
 ![pedrito](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/47becbd523052640880323581fa13ab3293a96ba.png)

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [September 3, 2018, 11:16am UTC](https://discourse.processing.org/t/how-i-can-do-score/3223/4 "2018-09-03T11:16:21Z")

</div>

You probably need to clear the background then!

Add:

```auto
  background(255);

```

As the first line of `draw()`.

---

<div class="post-metadata">

**Author:** ![Pedro](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pedro](https://discourse.processing.org/u/Pedro)\
**Post date:** [September 3, 2018, 11:17am UTC](https://discourse.processing.org/t/how-i-can-do-score/3223/5 "2018-09-03T11:17:41Z")

</div>

You are the best…
