# I need help solving this strange variable scope error

So, we all know the common error “local variable ‘yVel’ referenced before assignment”. I got this error, but this time it is different. I am referencing my “yVel” variable outside of the processing draw function, and inside the processing draw function I am saying “yVel += gravity”. I don’t know how to fix this because I cant put the variable in the draw function, because then it would just keep resetting the variable. And yes, I did try using python globals, and those didn’t work either. And, just to test, I defined the variable in the draw function, and it didn’t show another reference error for the “gravity” variable, so I know I can reference variables outside of the draw function. Here is my script:

``````width = 1000
height = 1000
#Variables
x = random(0,width)
y = random(0,height)
xVel = random(-10,10)
yVel = random(-0.5,0.5)
gravity = random(0,1)
elasticity = random(0,1)
friction = random(0,1)

def draw():
yVel += gravity
x += xVel
y += yVel
xVel =- xVel*elasticity
xVel =- xVel*elasticity
if x < float(radus/2):

else:
if x > width-float(radius/2):

if y < float(radus/2):

else:
if y > width-float(radius/2):

xVel *= friction

`global x, y, xVel, yVel, radius`