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

How can you display the name of a function (NOT a built-in one) in a Gui?

Asked by 6 years ago

I've tried this:

function RandomFuncThatDoesNothing()
    -- Some random code
end
print(tostring(RandomFuncThatDoesNothing())

Does not work out so well for me.

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
6 years ago

Function values don't have names. Your code is equivalent to

RandomFuncThatDoesNothing = function() end

ie, the name is not part of the function itself; you've just save the function itself to some variable.


If you want to have a collection of functions identified by their name, use a table and keep their keys in your variables:

local SPECIAL = {
    alpha = function() end,
    beta = function() end,
}

local f = "alpha"

-- To call f
SPECIAL[f]("hi")

print(f) --> alpha, since f is actually just a string
Ad

Answer this question