So I want to figure out how to make random functions, this can be useful to make a game like Horrific Housing.
function One() print("1") end function Two() print("2") end function Three() print("3") end local functions = {One(), Two(), Three()} math.random(1, #functions)
I'm using strings because it shows whats happening. When you run this, it'll print all the numbers that are there, is there a way to fix this?
You can store your functions invariables like so:
one = function() print("1") end two = function() print("2") end three = function() print("3") end
then put those variables in a table:
local functions = { one, two, three }
and pick a random function in that table/call that function
randomFunction = functions[math.random(1, #functions)] randomFunction()
All together, it would look like this:
one = function() print("1") end two = function() print("2") end three = function() print("3") end local functions = { one, two, three } randomFunction = functions[math.random(1, #functions)] randomFunction()