Find index of function stored in dictionary from inside of that function

I was writing a script that stores the functions of all the items in my game, and was wondering if it’s possible to do something like this:

local dictionary = {
	["func1"] = function()
		print(???)
		--Outputs "func1" without putting in print(“func1”) directly
	end;
	
	["func2"] = function()
		print(???)
		--Outputs "func2" without putting in print(“func2”) directly
	end;
}

Here’s the actual section of the script I am working on, perhaps it makes my question more clear:

module.ItemFunctions = {
	["Adventure Card"] = function()
		if animationTrack.IsPlaying then
			remotesFolder.RemoveAccessory:FireServer("Adventure Card")
			--Can I just grab the name from the dictionary this function is stored in somehow?
			animationTrack:Stop()
		else
			remotesFolder.AddAccessory:FireServer("Adventure Card")
			--Same here
			animationTrack:Play()
			task.wait(animationTrack.Length * 0.8)
			animationTrack:AdjustSpeed(0)
		end
	end;
}
3 Likes

You could index its name using a pairs loop.

for i, v in pairs(dictionary) do
    print(i) --this would print "func1"
end

I’m not quite sure what you’re trying to do though. This is just a general example of how to use a pairs loop in a dictionary.

1 Like

[This reply was moved into the post itself]

2 Likes