How can i determine the name of a function inside of a table?

I am trying to figure out how to determine the name of a function inside of a table.

for example.

Thanks in advance!


local function f1()
--function one
end

local function f2()
--function two
end

local function f3()
--function three
end

local Funcs = {f1,f2,f3}


for a, b in ipairs(funcs) do
if b.Name == ("f3") then --how would i do this??


end
end

1 Like

can you even put functions into tables???
if you can i would do this

local Funcs = {
	Func1 = f1,
	Func2 = f2,
	Func3 = f3
}
2 Likes

In a array you wouldn’t be able to figure out the name of the function
If it was a dictionary you could check the index

Like this.

Also yes you can.

did not know that wow
what would you even be able to do with them

1 Like

Can you show me an example please?

1 Like

they said my post was the example lol

2 Likes

This is off topic so I’ll keep it short.
You could make custom classes with their own events/functions or export them from module scripts.
Quick example would be

local commands = {}

commands.ban = function(player)
    player:Kick("Banned")
end

commands.kick = function(player)
    player:Kick("Kicked")
end

The custom classes explanation is pretty advanced and there are other topics on it so I’ll just link to the best one.

All about Object Oriented Programming

1 Like

I’ll include checking the index

local function f1() end
local function f2() end
local function f3() end
 
local functions = {
    ["f1"] = f1;
    ["f2"] = f2;
    ["f3"] = f3;
}

for index, func in pairs(functions) do
    if index == "f3" then
        --// do something
    end
end
1 Like

honestly dont think this is that off topic, this might help OP fix his problem

2 Likes

You’re probably right but it was slightly off topic as OP was just asking a simple question and not asking how OOP works lol.

1 Like

Hey just a question, but im trying to print(index) inside of the for loop but its not printing anything?

Probably unlikely but does it matter im on a local script??

1 Like

No the type of script doesn’t matter.
Can you show me your for loop?
Because the code I sent works fine for me.

1 Like

local function Disfunction()
end

local function PosionousPremesis()
end


local Powers = {
	["Disfunction"] = Disfunction();
	["Posionous Premesis"] = PosionousPremesis();
}


	uis.InputBegan:Connect(function(key)
		
		if key.KeyCode == Keybind or key.KeyCode == Keybind2 then 
			print("Pressed")--prints
			
			for index, TempFunction in pairs(Powers) do
				print(""..index)--doesnt print
				
				
			end
		
			
			
			
			
		end
	end)	












Remove the () from the functions you’re running them and setting the indexes to what they return which is nil and removes the indexes from the dictionary.

1 Like

WOW [facepalm]. Thanks for the time.

1 Like