Hi i’m new to the forums and to Codea.
So i’m seeing weird results. I have a 6x6 grid and i assign the starting point within the grid and i have a function that gives me a random exit point in the grid that is at minimum 5 squares away. The problem is sometimes when i run and rerun (using the little recycle circle arrow) the Exit values don’t match the values just before the findExit returns ex and ey.
This is from the grid:init for the class
local exitx, exity = 0,0
local hx,hy = 0,0
hx,hy = math.random(1,6), math.random(1,6)
exitx, exity = findExit(hx,hy)
print("exit " .. exitx .. "," .. exity)
This is my findExit function…i have tried different things, but i get weird results sometimes. you can see the different values in the print(“end” and print(“exit” sometimes, and i can’t for the life of me figure out why. Also, if i do it as below with the 2nd return ex, ey i sometimes get nil values in the exitx or exity variables, despite the ex and ey variable showing a value
function findExit(sx,sy)
print("start " .. sx .. "," .. sy)
local ex,ey = math.random(1,6), math.random(1,6)
if math.abs(sx-ex) + math.abs(sy-ey) >= 5 then
print("end " .. ex .. "," .. ey)
return ex, ey
else
findExit(sx,sy)
end
--return ex, ey
end