# Troubles with variables

**URL:** <https://discourse.processing.org/t/troubles-with-variables/9383>\
**Category:** Beginners\
**Created:** [March 17, 2019, 3:32pm UTC](https://discourse.processing.org/t/troubles-with-variables/9383 "2019-03-17T15:32:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raidzor](https://avatars.discourse-cdn.com/v4/letter/r/58f4c7/32.png) [@Raidzor](https://discourse.processing.org/u/Raidzor)\
**Post date:** [March 17, 2019, 3:32pm UTC](https://discourse.processing.org/t/troubles-with-variables/9383/1 "2019-03-17T15:32:17Z")

</div>

Being a beginner, I struggle to understand the structure you have to put variables in to actually make them work. Let’s suppose I have to create an object, an ellipse, that moves with constant speed, or even acceleration. For that, I create variables, v, t and x.  
x is the actual variable that sets the x coordinate on the canvas, v is speed and t is time.  
So I put everything together, and when I put x as the x coordinate of the shape, it tells me that x is not defined. I know this is, with great probability, one of the most stupid and elementary questions ever asked, but if you could link me to somewhere where I could learn how to use and place variables in the code correctly that would be greatly appreciated and more than enough. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![cansik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cansik/32/8815_2.png) [@cansik](https://discourse.processing.org/u/cansik)\
**Post date:** [March 18, 2019, 2:27pm UTC](https://discourse.processing.org/t/troubles-with-variables/9383/2 "2019-03-18T14:27:46Z")

</div>

As a first recommendation: showing a simple example (actual code) which shows what you would like to do, helps others to understand your problem. Because at the moment I can just guess your problem, which is not the most efficient way to help you.

But it seems that you struggle with the OOP concepts. Check out the [class example](https://processing.org/reference/class.html) of the processing help page.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [March 18, 2019, 3:26pm UTC](https://discourse.processing.org/t/troubles-with-variables/9383/3 "2019-03-18T15:26:23Z")

</div>

i understand that the question is

- p5.js ( not processing IDE / JAVA mode )
- about variables ( not objects and classes )

the very basic is

- that variables have to be defined.
- and it matter where you define them and where use them.

see this code  
[https://editor.p5js.org/kll/sketches/bh83epBn8](https://editor.p5js.org/kll/sketches/bh83epBn8)  
where x,y,v,t are “global” defined and set.  
while x later is changed in a subroutine  
move\_it()

the function draw ( default try to run with 60 frame ( times ) per seconds )  
and calls

- clean up the canvas
- the draw of a circle “draw\_it()”
- and call the change of x “move\_it()” what actually is for the next run.
