Function concatenation

This is more of a LUA based question, but short and sweet:

Say I have 10 functions and I want to randomly select 3 of those functions to run. Would it be possible to concatenate these functions such that during the initialization stage I could select the 3 functions and prevent myself from having to do 10 checks over and over again?

E.g.,

[lua]local func1 = math.random(1,10)
local func2 = math.random(1,10)
local func3 = math.random(1,10)

–local allFuncs = func1 + func2 + func3[/lua]

Something like that. Is this possible? To have moving modules of code? :slight_smile: [import]uid: 52208 topic_id: 18575 reply_id: 318575[/import]

i dont think you can concatenate function names
you may want to store your functions in table and then iterate through it to randomly call functions, just my 2 cents [import]uid: 16142 topic_id: 18575 reply_id: 71333[/import]

I think I’ve found a solution but I’m struggling at the process of “copying” functions and getting them to run.

[lua]–Array containing the names of all my functions

local funcArray= {
{ id=“1”, active=false, func = fasterPlatformRegen },
{ id=“2”, active=false, func = moreMultipliers },
{ id=“3”, active=false, func = differentNumberOfPlatforms }
}

–Sample of an actual function
function fasterPlatformRegen()
print(“Faster platforms!”)
end

–Where I randomly call the functions. The math.random logic left out for simplicity, but you get the idea…
function callTheRandoms()
local function() = funcArray[1].func
end[/lua]

So my logic here is to randomly choose X functions from funcArray and then gather the function names and just call them one after another. For instance, if I want to call 3 random functions back to back, I’d choose 3 functions from the funcArray and then call them in another function. Does that make sense?

The part where I’m getting hung up is after I’ve chosen the random functions from the array and I go to call them later, I’m getting syntax errors. Any suggestions? [import]uid: 52208 topic_id: 18575 reply_id: 71614[/import]

Is this something you need? I never did anything like that, but it is calling three function in randomly fashion

[lua]function foo1()
print(“i am foo1”)
end

function foo2()
print(“i am foo2”)
end

function foo3()
print(“i am foo3”)
end

local funcTable = {

{func = foo1},
{func = foo2},
{func = foo3}

}

local function return_funcs()

local one = funcTable[math.random(1,3)].func()
local two = funcTable[math.random(1,3)].func()
local three = funcTable[math.random(1,3)].func()

return one,two,three
end

local function executeall()

local one,two,three = return_funcs()

end

executeall()[/lua] [import]uid: 16142 topic_id: 18575 reply_id: 71617[/import]

This is exactly what I’m looking for! Thanks a bunch :smiley: [import]uid: 52208 topic_id: 18575 reply_id: 71632[/import]

ah, it was a cool experience for me anyway) if you need faster help, it will be easier to look at this topic:
http://developer.anscamobile.com/forum/2011/12/02/lets-be-friends

[import]uid: 16142 topic_id: 18575 reply_id: 71635[/import]