Can anyone tell me why this code is not working
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
elseif y>-50 then
sprite("Documents:the taco",x, y, 100, 74)
function touched (touch)
if touch.state==BEGAN and y<0 then
if x>350 and x<450 and y>250 and y<350 then
@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.
@newow You don’t need to start a new discussion for the same program. You could have asked this question in your original discussion “Help”.
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.
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