Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

I've tried this:

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

Does not work out so well for me.

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.