# Score counter Help

**URL:** <https://discourse.processing.org/t/score-counter-help/11587>\
**Category:** Coding Questions\
**Created:** [May 25, 2019, 1:43pm UTC](https://discourse.processing.org/t/score-counter-help/11587 "2019-05-25T13:43:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobby](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Bobby](https://discourse.processing.org/u/Bobby)\
**Post date:** [May 25, 2019, 1:43pm UTC](https://discourse.processing.org/t/score-counter-help/11587/1 "2019-05-25T13:43:52Z")

</div>

Hi, i have made a program to where balls would enter a basket and for every ball that enters (5 balls) + 10 to the counter and the balls would reset to the start.

I made my balls in an array:

```auto
Ball[] bballs = new Ball[5];

void setup(){
  size(640,480);
  
  // create balls
  for(int i = 0; i<bballs.length; i++) {
    bballs[i] = new Ball();
  }
}

```

The problem is that when all the balls are sent into the basket at the same time, the counter would only update by +10 instead of +50.  
If 1 ball was to enter by itself it would rarely update.  
Any reason to why this is happening?

---

<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:** [May 25, 2019, 1:49pm UTC](https://discourse.processing.org/t/score-counter-help/11587/2 "2019-05-25T13:49:07Z")

</div>

Without seeing the code that detects when a ball has entered the hoop, we are at a loss to help you. Ideally, you detect when a ball enters the hoop, and mark that ball as having entered - so you don’t count it again. You clear that it has been counted when it exits the hoop.

And you should have a counter that remembers how many balls have gone in. Once that counter reaches the amount required, score points are awarded and the counter’s value decreases.

---

<div class="post-metadata">

**Author:** ![Bobby](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Bobby](https://discourse.processing.org/u/Bobby)\
**Post date:** [May 25, 2019, 1:51pm UTC](https://discourse.processing.org/t/score-counter-help/11587/3 "2019-05-25T13:51:17Z")

</div>

Basket is on the bottom right of screen

```auto
if ((pos.y >380) && (pos.x >560)){ //resets ball if in basket
      pos.x = random(0,26);
      pos.y = random(0,5);
      vel.x = random(1.15,1.2);
      vel.y = random(0.2,1.2);
      score = score + 10;

```

---

<div class="post-metadata">

**Author:** ![Bobby](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Bobby](https://discourse.processing.org/u/Bobby)\
**Post date:** [May 25, 2019, 1:56pm UTC](https://discourse.processing.org/t/score-counter-help/11587/4 "2019-05-25T13:56:02Z")

</div>

The balls bounce off a platform controlled by player and has to land in basket.

I do not understand how i can track/mark when a ball has entered, and how to implement a counter that remembers how many balls have gone in.

---

<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:** [May 25, 2019, 2:38pm UTC](https://discourse.processing.org/t/score-counter-help/11587/5 "2019-05-25T14:38:56Z")

</div>

Instead of just awarding ten points for every ball, remember how many balls have gone in:

```java
if ((pos.y >380) && (pos.x >560)){ //resets ball if in basket
      pos.x = random(0,26);
      pos.y = random(0,5);
      vel.x = random(1.15,1.2);
      vel.y = random(0.2,1.2);
      //score = score + 10;
      counter = counter + 1;
}

```

Now when enough have gone in, adjust the score and counter:

```auto
if( counter >= 5 ){
  counter = counter - 5;
  score = score + 50;
}

```

This then scores 50 points every five balls in, instead of 10 points for each ball.

---

<div class="post-metadata">

**Author:** ![Bobby](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Bobby](https://discourse.processing.org/u/Bobby)\
**Post date:** [May 25, 2019, 3:17pm UTC](https://discourse.processing.org/t/score-counter-help/11587/6 "2019-05-25T15:17:54Z")

</div>

I like this, I tried it in my code just like you did ( i had to make a new int counter; ).  
Now the score is not updating when balls go in.

Also the balls do not go in sometimes all at the same time due to them each having different velocities and that is why i want to give each ball an individual score. There is gravity with the balls.

E.g. when all the balls enter, you can see the score gradually increase instead of waiting for all balls to go in and then adding 50.  
Thank you for helping me 🙏

---

<div class="post-metadata">

**Author:** ![Bobby](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Bobby](https://discourse.processing.org/u/Bobby)\
**Post date:** [May 25, 2019, 4:14pm UTC](https://discourse.processing.org/t/score-counter-help/11587/7 "2019-05-25T16:14:08Z")

</div>

I see why, the score doesn’t increase.  
the score will increase by 10 once the balls have landed inside the basket 5.  
The balls are not acting as if they are all separate:thinking:
