[Help] Multiple arguments from onEvent button

Hi everybody,

I started with corona last week and I have some questions… anyone can help me, please?

The first one is about arguments passed to a function called by the onEvent from a button.

I want to pass two arguments to a function called by a button, but this not working out.

Here’s my code:

local function handleButtonEditarEvent( carta )

if ( “ended” == event.phase ) then

end

end

local function handleButtonAEvent( event )     if ( “ended” == event.phase ) then     carta = “A” button_editar = widget.newButton {     x = display.contentCenterX ,     y = 820,   id = “button_editar”,     onRelease = handleButtonEditarEvent(carta),     overFile = “”,     defaultFile = “image/editar.png”     }

end end

I need to pass this variable “carta” to the function “handleButtonEditarEvent”. How can I do this?

Thank you very much.

Add:

event.target.carta = carta
In your button event handler.

And in your other function, access it via:
event.target.carta

It doesnt work :frowning:

I did this:

local function handleButtonEditarEvent( event ) test = event.target.carta if ( "ended" == event.phase ) then print ("OK ") print (test) end end local function handleButtonAEvent( event )     if ( "ended" == event.phase ) then     carta = "A" event.target.carta = carta     button\_editar = widget.newButton {     x = display.contentCenterX ,     y = 820,   id = "button\_editar",     onEvent = handleButtonEditarEvent,     overFile = "",     defaultFile = "image/editar.png"  } ... end end

In the terminal I saw that “test” is nill

I did this right?

Thank you!

anyone else?

Your code was formatted badly in your first post so i didn’t see that.

This is how you would do it, based on your current code:

local function handleButtonEditarEvent( event ) test = event.target.carta if ( "ended" == event.phase ) then print ("OK ") print (test) end end   local function handleButtonAEvent( event )      if ( "ended" == event.phase ) then     carta = "A"  button\_editar = widget.newButton  {     x = display.contentCenterX ,     y = 820,   id = "button\_editar",     onEvent = handleButtonEditarEvent,     overFile = "",     defaultFile = "image/editar.png"  } button\_editar.carta = carta end end

It works!

Thank you very much! =)

Add:

event.target.carta = carta
In your button event handler.

And in your other function, access it via:
event.target.carta

It doesnt work :frowning:

I did this:

local function handleButtonEditarEvent( event ) test = event.target.carta if ( "ended" == event.phase ) then print ("OK ") print (test) end end local function handleButtonAEvent( event )     if ( "ended" == event.phase ) then     carta = "A" event.target.carta = carta     button\_editar = widget.newButton {     x = display.contentCenterX ,     y = 820,   id = "button\_editar",     onEvent = handleButtonEditarEvent,     overFile = "",     defaultFile = "image/editar.png"  } ... end end

In the terminal I saw that “test” is nill

I did this right?

Thank you!

anyone else?

Your code was formatted badly in your first post so i didn’t see that.

This is how you would do it, based on your current code:

local function handleButtonEditarEvent( event ) test = event.target.carta if ( "ended" == event.phase ) then print ("OK ") print (test) end end   local function handleButtonAEvent( event )      if ( "ended" == event.phase ) then     carta = "A"  button\_editar = widget.newButton  {     x = display.contentCenterX ,     y = 820,   id = "button\_editar",     onEvent = handleButtonEditarEvent,     overFile = "",     defaultFile = "image/editar.png"  } button\_editar.carta = carta end end

It works!

Thank you very much! =)