# I need help to keep score

**URL:** <https://discourse.processing.org/t/i-need-help-to-keep-score/21724>\
**Category:** Coding Questions\
**Created:** [June 10, 2020, 2:16am UTC](https://discourse.processing.org/t/i-need-help-to-keep-score/21724 "2020-06-10T02:16:53Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Pr0tonX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pr0tonx/32/2590_2.png) [@Pr0tonX](https://discourse.processing.org/u/Pr0tonX)\
**Post date:** [June 10, 2020, 10:11am UTC](https://discourse.processing.org/t/i-need-help-to-keep-score/21724/3 "2020-06-10T10:11:58Z")

</div>

Hi @mrporcessing,

as @josephh said, please take time to format your code when you post it ; it is more readable for people who will help you.

Concerning your issue, you have to check if the ball position in X axe exceeds the position of one of your pad :

```auto
    score1 += 10;
  }
  if (ball_posX >= pad1X){ // for right pad
    score2 += 10;
  }

```

But it seems that doing this, you won’t add only 10 points by winning once, but 70 because, loop goes 7 times before restart.  
Your actual conditon restart the game when the middle of the ball exceeds the position of the right pad, whereas the condition of giving point is validated when the corner of the ball exceeds, so the draws loops many times before the middle of ball exceeds it also.  
So you can change a little the condition to validate only once the scoring, according to your condition of restart :

```auto
  if (ball_posX <= 1) { // because you restart the game at ball_posX < 0, so add score the frame just before
    score1 += 10;
  }
  if (ball_posX >= width - ball_size - 1) {// because you restart the game at ball_posX > width - ball_size, so add score the frame just before
    score2 += 10;
  }

if (ball_posX < 0)||(ball_posX > screenX - ball_size){
// restart game
}

```

---

_[View the full topic](https://discourse.processing.org/t/i-need-help-to-keep-score/21724)._
