I'm trying to write a lua function in which I pass two rectangles coordinates and receive the values on polar coordinates. Somehow the code I wrote returns an error and I can't see where I went wrong. How do I fix it?
io.write("Enter first coord: ")
F = io.read()
io.write("Enter second coord: ")
S = io.read()
A = tonumber(F)
T = tonumber(S)
getPolar(A,T)
function getPolar(x,y)
mag = math.sqrt(x^2+y^2)
ang = math.atan(y/x)
return print("Magnitude: " .. tostring(mag) .. " Angle: " .. tostring(ang))
end
The error I receive is the following:
Polar.lua:9: attempt to call a nil value (global 'getPolar') stack traceback: Polar.lua:9: in main chunk [C]: in ?