Is it possible to store functions in a dictionary?

is it possible to store functions in a dictionary like

{
[“kill”] = (some function that would eventually set the player’s health to 0)
}

Ignoring any strange reason I have for this, is it possible? What’s the syntax? I’ve searched it up, can’t find anything.

3 Likes

You can

local dict = {
	["kill"] = function(text)
		print(text)
	end
}

--To retrieve

dict["kill"]("Print this please")
3 Likes

Yes it is possible

for example :

local dictionary = {}

function dictionary.FUNCTIONNAME()
     print('Test')
end

dictionary.FUNCTIONNAME()

Another example :

local dictionary = {
     FUNCTIONNAME = function()
          print('Test')
     end,
}

dictionary.FUNCTIONNAME()
2 Likes

just a question…

if i retrieve a function on another script knowing that function is in a module script and then a variable inside of that function is referencing to the original module script and then i change a bit that variable using a different script it was called in…

will the original module script be changed in some way?