JuniorMelo Posted February 13, 2016 Posted February 13, 2016 Hello,I have a doubt... it is possible to create a function that activates other functions randomly, using math.random Example local functions = {function1, function2} function reboot() for i,player in ipairs(getElementsByType("player")) do randomfunctions = math.random(#functions) setTimer( randomfunctions, 1000, 1, player ) end end function function1(player) end function function2(player) end ........... \__ ▄▂_ .........[█|||███████]▄▄▄▄▄▄▄▄▄▃▂ ..__▂▄▅█████████▅▄▃▂ I███████████████████] ...◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤ ░░░███████ ]▄▄▄▄▄▄▄▄ ▂▄▅████████▅▄▃▂ I███████████████████] ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤
Alexs Posted February 13, 2016 Posted February 13, 2016 (edited) U should store the functions on tables, then just access from a random generated index. Edited February 13, 2016 by Guest Developer @ MYVAL
Tomas Posted February 13, 2016 Posted February 13, 2016 It may work function func1() print("1") end function func2() print("2") end function func3() print("3") end local functions = {func1, func2, func3} function getRandomFunction () return functions[math.random(1, #functions)] end getRandomFunction()() EDIT: Fixed a typo Currently developing for International Gaming Community - Join us!
JuniorMelo Posted February 13, 2016 Author Posted February 13, 2016 Thanks ........... \__ ▄▂_ .........[█|||███████]▄▄▄▄▄▄▄▄▄▃▂ ..__▂▄▅█████████▅▄▃▂ I███████████████████] ...◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤ ░░░███████ ]▄▄▄▄▄▄▄▄ ▂▄▅████████▅▄▃▂ I███████████████████] ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now