I’m currently making a admin command gui/script, and I’m confused on how I would get a function name.
In this photo you can see that I have a function with a string name, and I wanted to get this string, so I used
print(cmdFunctions.testprint())
This however, prints… nothing. (it also runs the function, not what Im looking for)
One last thing, I have already tried to run
print(cmdFunctions.testprint)
And it just returned the function memory address (I believe thats what it is showing, but it doesnt really matter)
Because you’re printing a function, you’re calling the function inside another function, making the script thinks you’re trying to print out a function.
You technically already have the function “name”. When you do cmdFunctions.testprint(), “testprint” is the name
local name = "testprint"
local func = cmdFunctions[name]
print("Function name:", name)
func()
You can use a for loop and iterate the cmdFunctions dictionary which would give you every key (func name) and value (func) (if you’re trying to display all commands for example)
local cmdFunctions = {
testprint = function()
print("testprint function called")
end,
}
for name, func in pairs(cmdFunctions) do
print("Function name:", name) -- > Function name: testprint
func() -- > testprint function called
end