Log In  


So I'm currently trying to make a little game that features some fish being generated in a random spot in a pond, then swimming back and forth. As a start I've just been trying to generate the fish and have them point in the direction they will be going first. The random location generation worked fine, but when I tried to add the fx to flip the fish in the direction it's heading, I get the error 'unexpected symbol near '='' But I've been looking for a while and can't see where the issue is. The error is flagging the 'o.x+=1 and o.fx=true' and 'o.x-=1 and o.fx=false' lines

This is the offending chunk of code, thank you for any guidance!

function initfish()

fish1={
sp=6,
x=40+rnd(60),
y=40+rnd(60),
fx=false
}

end

function fishmove(o)
waypicker=rnd(2)
if waypicker==1 then
direction="left"
elseif waypicker==2 then
direction="right"
end

if direction=="left" then
o.x-=1 and o.fx=false
elseif direction=="right" then
o.x+=1 and o.fx=true
end
end
end

function updatefish()
fishmove(fish1)

end



1

Why do you have the "and" in there? I would think it should be:

if direction=="left" then
  o.x-=1
  o.fx=false
elseif direction=="right" then
  o.x+=1
  o.fx=true
end

Thank you! this has resolved the error alongside removing some unneeded 'end's, but my flip still isn't working so I'll have to investigate further


1

My guess is that the problem is your rnd(2) call. That will do two things you probably don't want: return a non-integer number and return a value between 0 and 1.9999 (so never 2). To make that work, try this:

-- use flr() to get an int value, and add one to get 1 or 2 instead of 0 or 1
waypicker=flr(rnd(2)) + 1

Ahh this makes sense, thanks so much!



[Please log in to post a comment]