butts = []
button={title:"RUN DEMO" , action:AutoPaint, sec:"demo", } : butts.Push(button)
butts[index].action(varr, m )You can see, this way requires me to have the same function parameters for all the buttons. I can of course get around this in a clunky way using the button index, but I'm wondering if there is a slick way that allows me to put the function parameters in the array somehow?
"squirreltown" wrote:
I have an array of aa's that are a part of a settings screen, 20 different buttons that do different things. I'm calling a function from each button. In the below Autopaint is a function being called.butts = []
button={title:"RUN DEMO" , action:AutoPaint, sec:"demo", } : butts.Push(button)butts[index].action(varr, m )You can see, this way requires me to have the same function parameters for all the buttons. I can of course get around this in a clunky way using the button index, but I'm wondering if there is a slick way that allows me to put the function parameters in the array somehow?
Thanks
"Rek" wrote:
What exactly are you trying to achieve? You could pre-cache all the arguments if they will always be the same for all button actions.
if index = 0
butts[index].action(one set of params)
else if index = 1
butts[index].action(other set of params)
end if
butts[index].action(butts[index].params)
butts = []
button={title:"RUN DEMO" , action:AutoPaint, sec:"demo", params:{param1: arg1, param2: arg2}} : butts.Push(button)
butts[index].action(butts[index].params)
b = butts[index]: b.action(b.params)
"belltown" wrote:butts = []
button={title:"RUN DEMO" , action:AutoPaint, sec:"demo", params:{param1: arg1, param2: arg2}} : butts.Push(button)
butts[index].action(butts[index].params)
butts[index].action(butts[index].params)and not at the Line# of the function it's calling which does have 2 parameters.
"squirreltown" wrote:"belltown" wrote:butts = []
button={title:"RUN DEMO" , action:AutoPaint, sec:"demo", params:{param1: arg1, param2: arg2}} : butts.Push(button)
butts[index].action(butts[index].params)
Rats. I tried that and it didn't work, it threw "wrong # of Func params" here:butts[index].action(butts[index].params)and not at the Line# of the function it's calling which does have 2 parameters.
That aside, the function parameters (inside the parenthesis) should accept some sort of AA?
function action (params as object) as void
p1 = params.param1
p2 = params.param2
' etc ...
end function
"belltown" wrote:
If you wrap the parameters in an AA, you can have as may as you want without changing the call to 'action'; just add them to the 'params' AA when you set up your buttons, and write whatever code you need in 'action' to handle them.
butts[index].action()
function action() as void
p1 = m.params.param1
p2 = m.params.param2
etc.
butts[index].params.param1 = something
butts[index].params.param2 = something_else
butts[index].action()