After learning 1% of tables and the fact that you cannot pass functions through RemoteEvents, I realized I had to make my custom DevConsole commands in the ServerScript.
I want them to be formatted something like this:
local Commands = { -- module
"print something" = { -- the command
desc = "print stuff", -- the description
func = function() -- the function to execute when called
print("yes")
end,
}
}
return Commands
And I want to access and run the func, when I want to. But how would I do these?
I am asking on how I would format the code above, since it’s obviously not correct. I’ve seen this done in the past, I suppose with guns, and I would like to do it too. I would want to know how to access and run the function linked in the table too.
local Commands = { -- module
["print something"] = {
desc = "print stuff", -- the description
func = function() -- the function to execute when called
print("yes")
end,
}
}
Commands["print something"]["desc"] --This is how you would get Desc
Commands["print something"].func() -- This is how to call func from the table
local Commands = { -- module
["print something"] = { -- the command
desc = "print stuff", -- the description
func = function() -- the function to execute when called
print("yes")
end,
}
}
return Commands
You do Commands["print something"].func() to acces it
-- Define functions here
local function func1()
--Do something
end
local function func2()
--Do something
end
-- Put functions in list
local list = {func1, func2}
-- Run function from list here
list[2]() -- This should run function 2
list[1]() -- This should run function 1