function setup()
x=0
y=-50
w=400
t=300
speedY=-7
end
function draw()
background(220, 174, 23, 255)
sprite("Documents:Mexican Guy", w, t)
if x>350 and x<450 and y>250 and y<350 then -- compare x,y positions
y=-50
elseif y>-50 then
sprite("Documents:the taco",x, y, 100, 74)
y=y+speedY
end
end
function touched (touch)
if touch.state==BEGAN and y<0 then
x=touch.x y=touch.y
end
end
if x>350 and x<450 and y>250 and y<350 then
w=450
end
@newow The if statement at the end of your code is outside of any function. It gets executed before any function and since x and y have no values yet, you get the “nil” error.
I don’t get why x and y don’t have values. They have values up at the top near the setup function. And why did the same line of code work just a few lines above, how come x and y have values for the first one
X and Y don’t have values because they haven’t been assigned yet. Since the if statement is outside of all the functions, it looks like it would come after setup, but it gets called first so x and y are still nil…
P.S. Your code is pretty messy, maybe try formatting it better.
x and y don’t have values when the conditional is tested because the setup function has not yet been run. It is only run after all of the code is read in, so any direct statements occur before anything in setup.