So I’ve been making function variables like
local Test = function ()
and I just found out there’s one to do like
local function Test()
what’s the difference between these two? If there is one, which should I be using?
So I’ve been making function variables like
local Test = function ()
and I just found out there’s one to do like
local function Test()
what’s the difference between these two? If there is one, which should I be using?
They are identical as far as I’m concerned; they both declare a function and store a local reference to it
Use whatever you prefer
"There is a difference in their scopes.
local function Test()
Can be accessed as an upvalue for recursion, while the other one can not."
Taken from this response, suggest reading through it:
local function Function1()
Function1() -- You can call itself
end
local Function2 = function()
Function2() -- You can't call itself
end
local function Function1()
Function1() -- You can call itself
end
local Function2 = function()
Function2() -- You can't call itself
end
local Function3; Function3 = function()
Function3() -- You can call itself
end