Jump to content

Question !!


JuniorMelo

Recommended Posts

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 

Link to comment

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

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...