I have a problem with functions

M\_LUA: local M = {} local function M:checkLevel(lvl) print(tostring(lvl) -- lvl = NIL local lvl = lvl; print(tostring(lvl)); -- lvl = NIL end MAIN\_LUA: local M = require = ("M"); -- main function --........ M.checkLevel(1) local Level2 = 2; M.checkLevel(Level2); --........

checkLevel(1) and checkLevel(Level2) both print that lvl(M_Lua) is NIL. Why? 

THANKS!

Hey volkenardt,

the problem is, that you are mixing up dot and colon operators.

If your function notation is:

function M:checkLevel(lvl)

you also have to use colons in the call:

M:checkLevel(1)

or

M.checkLevel(M, 1)

The reason for this is how LUA handle these function calls.

Look at this tutorial for in depth information:

https://coronalabs.com/blog/2015/12/01/tutorial-understanding-the-colon-vs-dot-operator/

Hey volkenardt,

the problem is, that you are mixing up dot and colon operators.

If your function notation is:

function M:checkLevel(lvl)

you also have to use colons in the call:

M:checkLevel(1)

or

M.checkLevel(M, 1)

The reason for this is how LUA handle these function calls.

Look at this tutorial for in depth information:

https://coronalabs.com/blog/2015/12/01/tutorial-understanding-the-colon-vs-dot-operator/