Troubles with variables

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.

1 Like

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 of the processing help page.

1 Like

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
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.
1 Like