I wouldn't recommend structuring your data quite like that for a situation like this. Mostly for readability and cleanliness of code, but also because it's just not practical.
For starters, constructing a new table with no reference as a key in a key/value pair is sort of useless -- since you have no reference to the key to retrieve the value. Tables in Lua are considered objects, therefore indexing Cmd with a different array of {"respawn", "re"} will result in a logic error (that key will not exist in the table).
Recommendation
Instead, I would recommend structuring your command data like so:
local commands = {
{{"respawn", "re"}, function(self, ...)
end)},
{{"kill", "k"}, function(self, ...)
end)}
}
(where self refers to the player executing the command, and ... represents the command arguments)
This way, you have the consistency of any entry in the command table following a command_alts = command[1]; run_command = command[2] format. You also have the added bonus and convenience of maintaining an array structure to your table, which usually makes development life easier.
Specificity
I did notice, however, that you've added some additional information about each command in your table. To accommodate this, I've made some adjustments:
local commands = {
{
alts = {"respawn", "re"},
description = "reloads the character model",
run = function(self, ...)
end,
}
}
...and follow a pattern a bit like that. We're basically just keeping an array of dictionaries; each dictionary being the data of a new command.
Hope this helps, let me know if you have any questions.
3 comments
How would i call the command would i do commands[cmd] or what?
Nvm found out how thanks a bunch
Also how would i make a command with more than 1 argument like a tp command