Ad
Log in to vote
1

How to call a random function within a table with parameters? [Solved]

Asked by 20 days ago
Edited by greatneil80 18 days ago

I don't really know how to explain this well, but I'm trying to call a function with a table, but the function has parameters. Heres what I've got (ignore the names)

commands[table.find(commandNames,command)](params)

commands[table.find(commandNames,command)] gets the function it needs, and I can leave it on its own to call the function but when I try to add parameters, it breaks, and says "attempt to call a nil value"

Anybody know how to fix this?

1 answer

Log in to vote
0
Answered by 20 days ago

Nevermind, found the issue. You can't put a number in a table of functions and expect it to call the function with that number as the index in the function

Correct way of doing it was instead of find the actual name of the function within that list which would instead look like

commands[commandNames[table.find(commandNames,command)]](params)
Ad

Answer this question