• How to make function with a function as an argument.
    2 replies, posted
I would love to learn how to make a function with function as an argument, like a nested function. I've searched for an hour now, and i still havn't found anything helpful, so i was hoping you guys could help me. You know when you fx. want to make a timer, it looks like this. [CODE]timer.Create(identifier, delay, repetitions, func)[/CODE] I was trying to find the source to this function in gmods files, but i couldn't. This is what i am looking for. [CODE]local function DoSomething(func) --Excacute the argumented function end DoSomething(function() print("hello") end)[/CODE] No matter how i wrap my mind around it, i just cant figure it out. Anyone know how to do this? :)
You basically answered your own question. Assuming the proper checks to make sure that first argument is a function, you'd just do: [code] local function DoSomething(func) func( ) end [/code]
[QUOTE=kpjVideo;52602456]You basically answered your own question. Assuming the proper checks to make sure that first argument is a function, you'd just do: [code] local function DoSomething(func) func( ) end [/code][/QUOTE] I feel stupid now xD Thanks for the reply my friend :) Worked like a charm :)
Sorry, you need to Log In to post a reply to this thread.