Is there a way to find out how many arguments a function takes in? In this case the script is sent an unknown function and I need to know how many arguments there are so I don’t get an error or leave them as nil.
For example (Not the same script, but same problem):
local functions = {}
function functions.a(x, y, z)
function functions.b(x, y)
function functions.c()
function functions.d(a, b, c, d, e)
local randomFunc = functions[math.random(0, #functions)]
randomFunc() -- Unknown amount of arguments
It looks like for your example this might be the way to go.
local functions = {
a = {3, function blah},
b = {2, function blah},
c = {0, function blah}
}
If I’m being honest though, I feel like this should just be handled differently. I mean if the arguments are XYZ for some of the functions and ABCDE for others, you need to know which arguments go where if you’re calling randomFunc. It looks more to me like you should just switch to if statements and ditch the function table.
Thanks, didn’t think of putting the amount in a table like that. Also, in my actual case I do know the order of the arguments - probably not the best example on my end, but oh well.