Add multiple arguments to a function?

I’m trying to make a tap listener to a function that uses the button’s assigned number to set it as another image. I have 5 buttons to press, and I’m trying to make it so that when you click on a button, an image on the side will take that buttons image. My question is how to make an event listener that allows me to set what the variables ButtonName and Number are.

function DoSomething(ButtonName, Number) print(tostring(ButtonName)) print(tostring(Number)) end button = display.newRect(100,100,100,100) button.tap = DoSomething button:addEventListener("tap", button)

Generally you can’t control the parameters passed to event handlers. In your case since your doing a table listeners, DoSomething will get two parameters:  self and event. Self is the button itself. And event is a table the event dispatcher creates.

You could add values to the button object:

button.ButtonName = "SomeName" button.Number = someNumber

Then inside the function you could either reference:

self.ButtonName self.Number

or

event.target.ButtonName event.target.Number

event.target and self would be the same.

Rob

Generally you can’t control the parameters passed to event handlers. In your case since your doing a table listeners, DoSomething will get two parameters:  self and event. Self is the button itself. And event is a table the event dispatcher creates.

You could add values to the button object:

button.ButtonName = "SomeName" button.Number = someNumber

Then inside the function you could either reference:

self.ButtonName self.Number

or

event.target.ButtonName event.target.Number

event.target and self would be the same.

Rob