1.

Solve : [Lua] More help needed?

Answer»

So it's giving me
Code: [Select]C:\PROGRAM Files (x86)\Lua\5.1\lua.exe: T:\space\Game\bin\f.lua:19: attempt to p
erform arithmetic on a nil value
stack traceback:
T:\space\Game\bin\f.lua:19: in function 'theta'
T:\space\Game\bin\f.lua:38: in main chunk
[C]: ?
when it has clearly become a number multiple times. Any help would be grand.



f.lua 1 300 -300 300 0 0 0 130
Code: [Select]-- Testing Ground for Space Game
-- 1 = Find F_x, F_y, and F_z
-- 2 = Find Theta.x, Theta.y, and MAGNITUDE
-- 3 = Find magnitude of Gravity




grav = function(g,d)
--gravitation <Gravitaion> <distance>
if (g/d) == (1/0) then
RETURN g
ELSE
return(g/d)
end
end


theta = function(x1, y1, z1, x2, y2, z2)
local x = tonumber(x2) - tonumber(x1)
local y = tonumber(y2) - tonumber(y1)
local z = tonumber(z2) - tonumber(z1)
-- 1
if arg[1] == "1" then print(math.floor(grav(tonumber(arg[8]),x)+0.5) .."," ..math.floor(grav(tonumber(arg[8]),y)+0.5) .."," ..math.floor(grav(tonumber(arg[8]),z)+0.5) ) end


-- 2
if arg[1] == "2" then print("theta.x=" ..math.floor( ( math.tan( y / z ) )*1000+0.5 ) / 1000 ) end
if arg[1] == "2" then print("theta.y=" ..math.floor( ( math.tan( math.sqrt( y * y + z * z ) / x ) ) * 1000 + 0.5 ) / 1000 ) end
if arg[1] == "2" then print("magnitude=" ..math.floor( (math.sqrt( x * x + y * y + z * z ) ) * 1000 + 0.5 ) / 1000 ) end
-- 3
if arg[1] == "3" then print(grav(math.floor( (math.sqrt( x * x + y * y + z * z ) ) * 1000 + 0.5 ) / 1000, arg[8]) ) end
if arg[1] == "3" then print("theta.x=" ..math.floor( ( math.tan( y / z ) )*1000+0.5 ) / 1000 ) end
if arg[1] == "3" then print("theta.y=" ..math.floor( ( math.tan( math.sqrt( y * y + z * z ) / x ) ) * 1000 + 0.5 ) / 1000 ) end

end

arg = {...}
theta(tonumber(arg[2]),tonumber(arg[3]),tonumber(arg[4]),tonumber(arg[5]),tonumber(arg[6]),tonumber(arg[7]))
you to a new table and then access elements of that table. All elements of that table will be nil.Fixed it, It had to do with inputting things that couldn't be changed to numbers.



Discussion

No Comment Found