Function name combined with math.random

Good day everyone!

I want a game which should be infinite and you hop along a way, which is made of single different groups of objects and these objects should be ordered in different ways every time you restart. 

So I thought of functions to build these seperate objects like : function object1(), object2(), objectn()

Then I need a function which sorts the objects in different ways, so i thought of to just call the build functions in different order, so I need the function name which is “object” and the number after that, 1, 2, n, and I wanted to do that with math.random(). 

How do I call these functions, i had this till now : object … math.random(1,10)()

but it does not work.

Thank you for helping me!

something like this, then varying the contents of the table will vary the “distribution” of your functions

-- note NO parenthesis, these are not function CALLS, just refs to the funcs -- demo: objectN is twice as likely, for example local funcTable = { object1, object2, object3, objectN, objectN } -- now call one at random funcTable[math.random(#funcTable)]()

@jason,
 
Are you asking a new question?  If so, tips:
 

  1. Once you mark a question as answered, asking new questions at the end is unlikely to get a response.
     
  2. Don’t quote everything, just use @name question …    while quoting has its place, quotes are typically hard to read if they are more than a few lines and I know I for one ignore them.
     
  3. I think you goofed up and your question got embedded in the quote.  You can click the little light-switch (upper left) to switch to raw editing mode. to fix that.  i.e. re-edit the post, switch to raw mode, and move that bit outside the formatting blocks.

 
Finally, I think you asked ( re-stated )  " Do, you also know how I can randomly select functions?"
 

Your attempt was close, but this is the right way:

funcTable[math.random(1, #funcTable)]()

Please read the docs for math.random() to better understand the arguments it takes:

@op - already answered??  (or are you asking what an if statement is?)

@ed - one arg form is ok

something like this, then varying the contents of the table will vary the “distribution” of your functions

-- note NO parenthesis, these are not function CALLS, just refs to the funcs -- demo: objectN is twice as likely, for example local funcTable = { object1, object2, object3, objectN, objectN } -- now call one at random funcTable[math.random(#funcTable)]()

@jason,
 
Are you asking a new question?  If so, tips:
 

  1. Once you mark a question as answered, asking new questions at the end is unlikely to get a response.
     
  2. Don’t quote everything, just use @name question …    while quoting has its place, quotes are typically hard to read if they are more than a few lines and I know I for one ignore them.
     
  3. I think you goofed up and your question got embedded in the quote.  You can click the little light-switch (upper left) to switch to raw editing mode. to fix that.  i.e. re-edit the post, switch to raw mode, and move that bit outside the formatting blocks.

 
Finally, I think you asked ( re-stated )  " Do, you also know how I can randomly select functions?"
 

Your attempt was close, but this is the right way:

funcTable[math.random(1, #funcTable)]()

Please read the docs for math.random() to better understand the arguments it takes:

@op - already answered??  (or are you asking what an if statement is?)

@ed - one arg form is ok