Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there any way to execute a function that has been assigned as a value to a key?

Asked by 6 years ago

Hi.

So, I'm trying to make my own admin commands, and I find it rather redundant to say "if msg == 'blablabla' then" for each and every admin command I make. Instead, I find it better just to iterate over a dictionary where its keys are the command strings and they keys' values are the functions to execute.

But, I have no idea how I would execute those functions set as keys. Is there any way?

local cmdModule = require(script.CommandModule)

local cmds = {
    ["shutdown"] = cmdModule.shutdown()
}

player.Chatted:Connect(function(msg)
    for i, v in pairs(cmds) do
        if msg == i then
            -- ???
        end
    end
end)

Answer this question