Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: [Lua] More help needed  (Read 3854 times)

0 Members and 1 Guest are viewing this topic.

Lemonilla

    Topic Starter


    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
[Lua] More help needed
« on: November 02, 2013, 09:11:51 PM »
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]))
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: [Lua] More help needed
« Reply #1 on: November 02, 2013, 09:34:08 PM »
you to a new table and then access elements of that table. All elements of that table will be nil.
I was trying to dereference Null Pointers before it was cool.

Lemonilla

    Topic Starter


    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: [Lua] More help needed
« Reply #2 on: November 03, 2013, 03:11:37 PM »
Fixed it, It had to do with inputting things that couldn't be changed to numbers.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.