# Problem with a variable that doesn't work well between class definition and global variables

**URL:** <https://discourse.processing.org/t/problem-with-a-variable-that-doesnt-work-well-between-class-definition-and-global-variables/44905>\
**Category:** Coding Questions\
**Created:** [August 7, 2024, 11:46am UTC](https://discourse.processing.org/t/problem-with-a-variable-that-doesnt-work-well-between-class-definition-and-global-variables/44905 "2024-08-07T11:46:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rasabh](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@rasabh](https://discourse.processing.org/u/rasabh)\
**Post date:** [August 7, 2024, 11:46am UTC](https://discourse.processing.org/t/problem-with-a-variable-that-doesnt-work-well-between-class-definition-and-global-variables/44905/1 "2024-08-07T11:46:46Z")

</div>

i have a problem with the variable that i defined named ‘ballSpeed’ that i expected that it should become a greater number when mouse is pressed but it’s speed won’t change. on the other hand, other variables such as color and ballSize is working good.  
If anyone can help, I would be very grateful.

 ![Screenshot 2024-08-07 130817](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/f/5f271fb49ffe37f8922f92ff4889325a53fc7287.png)

> **["if"ing ball 2 copy by Rasaa -p5.js Web Editor](https://editor.p5js.org/Rasaa/sketches/O9kkMq-Nd)**
>
> A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.

---

<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:** [August 7, 2024, 11:52am UTC](https://discourse.processing.org/t/problem-with-a-variable-that-doesnt-work-well-between-class-definition-and-global-variables/44905/2 "2024-08-07T11:52:36Z")

</div>

You got 2 ballspeeds, one global and one in the class

Get rid of the global one and change the one in the cöass in mousePressed
