I was wondering if you could use a function as an argument to another function, like this…
AddCommand("Command Title", "Command Description", function()
-- What the command does.
end)
I’ve seen it being used before, in this situation I used “AddCommand” as if you were adding commands using an already existent function called AddCommand.
Returning Part:Dsetroy() would just be nil. As the normal Part:Destroy() doesn’t return anything. Are you wanting to return an action that then runs in next function call?
Well I’m trying to make a commandbar, I have everything already lined up but for future updates, I can’t be bothered to update it by adding functions. Adding commands with the function in the same line (like this)…
local function Oops(...)
local BANANA,MONKEY = ...
print(BANANA,MONKEY) -- robux 2
local t = {...}
print(t[1]) -- robux
return ({...})[1] -- robux
end
Oops('robux',2)
The way that you wish to accomplish creating commands is a little backwards to me. Because when you have a function call within the function call, it’s going to run when you do the AddCommand. You should have a table of the commands then call the function from the table.
Functions are first-class types in Lua, meaning variables can hold functions as values, functions can be passed to other functions as arguments, and functions can be returned from functions.
E.g.
local sum = 0
table.foreach(list, function(key, value) sum += value end)
or
function curry(func, arg)
return function(...)
return func(arg, ...)
end
end
local customPrint = curry(print, "My Print:")
customPrint("test") -- -> My Print test