two buttons acting on the same function?

how can i make two buttons acting on the same function?
what i what is a function that can increase or decrease a variable value. This function should be linked to two buttons (one for increasing the variable value and one for decreasing it) but how can i make the function able to distinquish the intervention of the buttons?

thanks

Hi @jepha.krampus,

This is very simple, but it depends on how you’re creating buttons.

If you’re using the Corona widget button, you can assign an “id” to each button and then, in the listener function, detect which button was pressed:

http://docs.coronalabs.com/api/library/widget/newButton.html

If you’re creating your own buttons, then the button which was tapped will be pointed to by “event.target” in the listener function. See this guide:

http://docs.coronalabs.com/guide/events/touchMultitouch/index.html

You might also choose to use a widget “stepper” which can easily decrease and increase a variable:

http://docs.coronalabs.com/api/library/widget/newStepper.html

In all cases, please see the examples that are provided and it should be easy to figure out.

Best regards,

Brent

hi brent,

thanks for your reply! wanted to go with the stepper but there’s something wrong… the decrement button does not to work!!!
It also appear with a more pale color thant the increment one… is any issue up?

bests

 

Fixed!
the “elseif” structure of the stepper was not working!!! replaced it with a simple “else” and now it works!!!

have to say that i already found this  problem also in other parts of my code (not related with the stepper). if i use an “elseif” structure that part of code does not work, if  replace it with an “else” structure it works perfectly

thanks for your attention 

bests

 

Hi @jepha.krampus,

This is very simple, but it depends on how you’re creating buttons.

If you’re using the Corona widget button, you can assign an “id” to each button and then, in the listener function, detect which button was pressed:

http://docs.coronalabs.com/api/library/widget/newButton.html

If you’re creating your own buttons, then the button which was tapped will be pointed to by “event.target” in the listener function. See this guide:

http://docs.coronalabs.com/guide/events/touchMultitouch/index.html

You might also choose to use a widget “stepper” which can easily decrease and increase a variable:

http://docs.coronalabs.com/api/library/widget/newStepper.html

In all cases, please see the examples that are provided and it should be easy to figure out.

Best regards,

Brent

hi brent,

thanks for your reply! wanted to go with the stepper but there’s something wrong… the decrement button does not to work!!!
It also appear with a more pale color thant the increment one… is any issue up?

bests

 

Fixed!
the “elseif” structure of the stepper was not working!!! replaced it with a simple “else” and now it works!!!

have to say that i already found this  problem also in other parts of my code (not related with the stepper). if i use an “elseif” structure that part of code does not work, if  replace it with an “else” structure it works perfectly

thanks for your attention 

bests