# How do I add score to my game?

**URL:** <https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246>\
**Category:** Coding Questions\
**Created:** [June 23, 2019, 5:54am UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246 "2019-06-23T05:54:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul321](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rahul321](https://discourse.processing.org/u/rahul321)\
**Post date:** [June 23, 2019, 5:54am UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246/1 "2019-06-23T05:54:17Z")

</div>

I’m new to processing and have been trying to make a game in which the character moves to the coordinates of mouse click and then stays there until it is called again. I have a “food” which moves to a random location whenever the character and the food overlap. I want to add a score function for this game but the problem I’m getting is that it keeps adding the score infinitely and not once. I want the score to increase if it consumes the food from right and decrease if it consumes it from the left, but it just keeps increasing until its infinity or decreasing till its 0. How do I solve this?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [June 23, 2019, 6:13am UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246/2 "2019-06-23T06:13:59Z")

</div>

Hi,

It seems that your conditions are too general and that there is always a condition that is fulfilled so your score is changing at every frame.

But to be sure, we would need to see the full code.

And please format your code when you copy some here =)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 23, 2019, 6:24am UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246/3 "2019-06-23T06:24:03Z")

</div>

> **[r/processing - How do I add score to my game?](https://www.reddit.com/r/processing/comments/c3zll2/how_do_i_add_score_to_my_game/)**
>
> 0 votes and 0 comments so far on Reddit

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 23, 2019, 10:00am UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246/4 "2019-06-23T10:00:41Z")

</div>

> [@rahul321](#):
>
> have a “food” which moves to a random location whenever the character and the food overlap

This seems to happen only once and works correctly. Maybe change the score in the code there?

Regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![rahul321](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rahul321](https://discourse.processing.org/u/rahul321)\
**Post date:** [June 23, 2019, 12:59pm UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246/5 "2019-06-23T12:59:43Z")

</div>

Reddit bad, processing community good.

---

<div class="post-metadata">

**Author:** ![rahul321](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rahul321](https://discourse.processing.org/u/rahul321)\
**Post date:** [June 23, 2019, 1:01pm UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246/6 "2019-06-23T13:01:20Z")

</div>

Hello,

I do have a food that moves to a random location every time the character overlaps it. I actually just uploaded my full code, so it is more clear now.

---

<div class="post-metadata">

**Author:** ![rahul321](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rahul321](https://discourse.processing.org/u/rahul321)\
**Post date:** [June 23, 2019, 1:03pm UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246/7 "2019-06-23T13:03:42Z")

</div>

Hello,

Thank you for replying, I just uploaded my full code. I just realized that I need the preformat option to format the text.

---

<div class="post-metadata">

**Author:** ![tribblesontoast](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@tribblesontoast](https://discourse.processing.org/u/tribblesontoast)\
**Post date:** [June 25, 2019, 10:28am UTC](https://discourse.processing.org/t/how-do-i-add-score-to-my-game/12246/8 "2019-06-25T10:28:53Z")

</div>

First problem, you are iterating the score in the draw loop as jb4x said. Remove score(); from the draw.

Now you want the score to increase when the face eats the food? Simplest solution is to call your score(); method when you move the face to a new position.  
Where do you move the food?

Hopefully this is clear.
