# Send 1 data from Processing to Python that changes in void draw() loop (NEED HELP)

**URL:** <https://discourse.processing.org/t/send-1-data-from-processing-to-python-that-changes-in-void-draw-loop-need-help/35241>\
**Category:** Coding Questions\
**Created:** [February 17, 2022, 4:25pm UTC](https://discourse.processing.org/t/send-1-data-from-processing-to-python-that-changes-in-void-draw-loop-need-help/35241 "2022-02-17T16:25:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![finchle99](https://avatars.discourse-cdn.com/v4/letter/f/838e76/32.png) [@finchle99](https://discourse.processing.org/u/finchle99)\
**Post date:** [February 17, 2022, 4:25pm UTC](https://discourse.processing.org/t/send-1-data-from-processing-to-python-that-changes-in-void-draw-loop-need-help/35241/1 "2022-02-17T16:25:59Z")

</div>

Hi,  
I’m new in Processing.  
How can I send only 1 data from Processing to Python every time I use _mousePressed == true_, the data changes in _void draw()_.  
I tried and every time I press the mouse, the data that was sent to Python was a string of data sticks together…  
For example, the data _ **i** _ would be: 1, then 2, then 3…, it changes in _void draw()_ loop; then I press the mouse when the time at _i=5_, Python received: _12345_.  
Please give me some suggestions/ideas to handle this, which command I should use to delete the previous datas, I only need the last data when I press the mouse.  
Thank you all!

---

<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:** [February 18, 2022, 6:29am UTC](https://discourse.processing.org/t/send-1-data-from-processing-to-python-that-changes-in-void-draw-loop-need-help/35241/2 "2022-02-18T06:29:16Z")

</div>

Don’t use the `mousePressed` boolean. Instead, use the `mousepressed()` function.

The boolean is true if the mouse is pressed, which could be for several iterations of the draw() loop per click.

But the function only happens once per click, which sounds like exactly what you want.

```auto
void setup(){...}
void draw(){...}
void mousepressed(){
  send_data(i++);
}

```

---

<div class="post-metadata">

**Author:** ![finchle99](https://avatars.discourse-cdn.com/v4/letter/f/838e76/32.png) [@finchle99](https://discourse.processing.org/u/finchle99)\
**Post date:** [February 20, 2022, 9:16am UTC](https://discourse.processing.org/t/send-1-data-from-processing-to-python-that-changes-in-void-draw-loop-need-help/35241/3 "2022-02-20T09:16:35Z")

</div>

Thank you very much @TfGuy44.  
I changed “i” to the global variable and added _mousePressed()_ function, “i” still changed in _draw()_ loop and then it works.  
Thank you again!!!

---

<div class="post-metadata">

**Author:** ![finchle99](https://avatars.discourse-cdn.com/v4/letter/f/838e76/32.png) [@finchle99](https://discourse.processing.org/u/finchle99)\
**Post date:** [February 20, 2022, 9:20am UTC](https://discourse.processing.org/t/send-1-data-from-processing-to-python-that-changes-in-void-draw-loop-need-help/35241/4 "2022-02-20T09:20:18Z")

</div>

One more “newbie” question, how can I use a variable in _draw()_ loop in a diffrent function, if that variable doesn’t declare as a global variable?  
Thank you!

---

<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:** [February 20, 2022, 6:08pm UTC](https://discourse.processing.org/t/send-1-data-from-processing-to-python-that-changes-in-void-draw-loop-need-help/35241/5 "2022-02-20T18:08:59Z")

</div>

You don’t. That’s the big difference between global variables and local ones. Only global variables can be accessed in all your sketch’s functions.
