# Have an event only happen for 1 frame

**URL:** <https://discourse.processing.org/t/have-an-event-only-happen-for-1-frame/35516>\
**Category:** Processing.py\
**Created:** [March 2, 2022, 7:18am UTC](https://discourse.processing.org/t/have-an-event-only-happen-for-1-frame/35516 "2022-03-02T07:18:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adora](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@adora](https://discourse.processing.org/u/adora)\
**Post date:** [March 2, 2022, 7:18am UTC](https://discourse.processing.org/t/have-an-event-only-happen-for-1-frame/35516/1 "2022-03-02T07:18:42Z")

</div>

Hi, so basically I want my code to be so that if my cursor is touching a circle, a score will be updated by one point only until the cursor leaves and touches the circle again. However, currently, a point keeps on being added for every frame that the cursor is on the circle. How can I change this? Thanks 🙂

Here is the relevant code:

```auto
circle(x, y, 20)
if dist(x, y, mouseX, mouseY) <= 20:
            score = score + 1

```

---

<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:** [March 2, 2022, 7:39am UTC](https://discourse.processing.org/t/have-an-event-only-happen-for-1-frame/35516/2 "2022-03-02T07:39:45Z")

</div>

Without clicking the circle, just hovering…?

---

<div class="post-metadata">

**Author:** ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)\
**Post date:** [March 2, 2022, 7:54am UTC](https://discourse.processing.org/t/have-an-event-only-happen-for-1-frame/35516/3 "2022-03-02T07:54:31Z")

</div>

You’ve already done half the work, good job! And you even correctly identified what your problem is: The condition you’ve created is true whenever the mouse is inside the circle. However, what you really want, is to **check whether the mouse was not in the circle the frame before, but is now**.

To do this, you can use the `pmouseX` and `pmouseY` variables. They tell you where the mouse was the frame before. You can read more on them here:

> **[pmouseX \\ Language (API)](https://py.processing.org/reference/pmouseX.html)**
>
> Python Mode for Processing extends the Processing Development Environment with the Python programming language.

Try and solve your problem with this information. If you still need help, feel free to ask! 😃
