Calling function from another function

Hi I need to do something like this:

local function new()

local example = function()

end

end

How to call “example” function? If I write example() it wont work… I also tried new.example(), but dont work…

I need to do this, because I reached limit of 200 variables in one function and this can solve my problem, because I need quite more than 200 variables…

Thanks.
[import]uid: 59968 topic_id: 19575 reply_id: 319575[/import]

this question comes up every now and then.
the problem when creating local functions inside functions is to get the scope right. In your case you have to call the “outside” function first to adress the “inside” function.

I hope you can make sense of this:

local foo = function(params)  
  
 local bar1 = function()  
 print("bar1!")  
 end  
  
 function bar2()  
 print("bar2!")  
 end  
  
 bar1() -- is local, only works here!  
end  
  
foo() -- must be called to declare bar2()...  
bar2() -- ...to make this call work  

a better approach would be to store your extra functions inside a table:

local myFuncTable = {}  
  
myFuncTable.myFirstFunction = function (param)  
 print ("WOOOT! It's a "..param )  
end  
  
myFuncTable.myFirstFunction ("BOY!")  

and the best approach is to ‘outsource’ this table into a module.

func.lua

local myFuncTable = {}  
myFuncTable.myFirstFunction = function (param)  
 print ("WOOOT! It's a "..param )  
end  
return myFuncTable -- returns the table with all the functions in it  

and require it in

main.lua

local myFuncs = require ("func")  
myFuncs.myFirstFunction ("BOY!") -- output: WOOOT! It's a BOY!  

hope that helps,
happy holidays!

-finefin [import]uid: 70635 topic_id: 19575 reply_id: 75607[/import]