Hi Pickion,
I personally always use the structure you outlined in “example 1” and here’s why: when you construct your functions that way, you can refer to those functions, from within those functions. For example:
local n = 1 local function openDoor(event) if n\<=5 then print("opened Door "..n.." times.") n = n+1 openDoor() else print("done opening door.") end end openDoor()
If you try to run that same function, but declare it using the structure local openDoor = function(event), it will not work. To the best of my knowledge, that’s the only real advantage of using one method over the other, but since there is no downside to using the method outlined above, it’s probably just a good habit to get into.
Here’s some more explanation on this subject, taken from http://lua-users.org/wiki/ScopeTutorial :
local function f() end -- is equivalent to local f f = function() end -- not local f = function() end the difference between the last two examples is important: the local variable still doesn't exist to the right of the = that gives it the initial value. So if the contents of the function used f to get a reference to itself, it will correctly get the local variable in the first and second versions, but the third version will get the global f (which will be nil, if not a completely unrelated value set by some other code).
Hope that helps. P.S. I saw you followed me on Twitter today - thanks! 