Page 1 of 1

bad argument #1 to 'cos' (number expected, got nil)

Posted: Thu Nov 01, 2018 9:39 pm
by manolo0185
Hello all.

Call me stupid, but I now simplified my failure condition to a point where I cant understand the problem at all. You're my last help with this physics test project!

If I run the attached love file, I get the following printout:

Code: Select all

main.lua:81  Angle = 0
vec2.lua:96  phi =
nil
Error: vec2.lua:98: bad argument #1 to 'cos' (number expected, got nil)
stack traceback:
        [string "boot.lua"]:637: in function <[string "boot.lua"]:633>
        [C]: in function 'cos'
        vec2.lua:98: in function 'rotate'
        main.lua:81: in function 'update'
        [string "boot.lua"]:509: in function <[string "boot.lua"]:493>
        [C]: in function 'xpcall'
if I place a print(Angle) before the rotate() function call inside main.lua, Angle contains 0, which is as expected.
A print(phi) inside the rotate function within vec2.lua prints "nil".

How can that be? is the argument not passed for some reason?

What did I do wrong?

Re: bad argument #1 to 'cos' (number expected, got nil)

Posted: Thu Nov 01, 2018 10:24 pm
by veethree
Line 81 in main.lua is

Code: Select all

Force.rotate(Angle)
but should be

Code: Select all

Force:rotate(Angle)

Re: bad argument #1 to 'cos' (number expected, got nil)

Posted: Fri Nov 02, 2018 8:00 pm
by manolo0185
Oops! I fell in once again!
Thanks!