A local function is able to access a global function but another function is not.Why?
local function a() go() end a() local function b() go() end local something=dis.... something:addEventListener("tap",b); function go() print("zzzz") end
function “a” produces an error.Function “b” works…But both are same type of functions right??
Use forward declaration instead of globals to solve scope issues:
local a local b local go a = function(num) go(num) end b = function(num) go(num) end go = function( num ) print("zzzz", num ) end a(1) b(2) go(3)
Regardless, you cannot call a function till it has been defined.
So, this would be wrong:
local a local b local go a = function(num) go(num) end b() b = function(num) go(num) end go = function( num ) print("zzzz", num ) end
This also works thanks to forward declaration:
Use forward declaration instead of globals to solve scope issues:
local a local b local go -- By the time the closures execute a,b, and go have been defined. timer.performWithDelay( 100, function() a(1) end ) timer.performWithDelay( 100, function() b(2) end ) timer.performWithDelay( 100, function() go(3) end ) a = function(num) go(num) end b = function(num) go(num) end go = function( num ) print("zzzz", num ) end
Use forward declaration instead of globals to solve scope issues:
local a local b local go a = function(num) go(num) end b = function(num) go(num) end go = function( num ) print("zzzz", num ) end a(1) b(2) go(3)
Regardless, you cannot call a function till it has been defined.
So, this would be wrong:
local a local b local go a = function(num) go(num) end b() b = function(num) go(num) end go = function( num ) print("zzzz", num ) end
This also works thanks to forward declaration:
Use forward declaration instead of globals to solve scope issues:
local a local b local go -- By the time the closures execute a,b, and go have been defined. timer.performWithDelay( 100, function() a(1) end ) timer.performWithDelay( 100, function() b(2) end ) timer.performWithDelay( 100, function() go(3) end ) a = function(num) go(num) end b = function(num) go(num) end go = function( num ) print("zzzz", num ) end