So with a normal table
normaltable = {"hello", 4, 100}
I can do
normaltable[math.random(1, #normaltable)]
and I will get a random value inside the table. However if I have functions like:
functiontable = {} functiontable.Print = function() print("hi") end) functiontable.Print2 = function() print("hello") end)
I cant use the random pick as I was for the first one as it can't get the length of the table. What would be an alternative to get a random function from a table of functions?
local function Print() print("hi") end local function Print2() print("hello") end local functiontable = {Print, Print2} -- Remember to use local variables. functiontable[math.random(1, #functiontable)]() -- Calls a random function ----OR---- local functiontable = {}-- Remember to use local variables. local function Print() print("hi") end local function Print2() print("hello") end table.insert(functiontable, Print) table.insert(functiontable, Print2) tablefunction[math.random(1, #functiontable)]() -- Calls a random function