How to reference a pressed button?

I have a table and I have a button, I would like to add the button to a table when it’s pressed.

local table = {} function btnPressed ()     // add the pressed button to the table table[#table+1] = ??? end local btn = widget.newButton({                  onPress = btnPressed })

It’s in the docs:

https://docs.coronalabs.com/api/library/widget/newButton.html#examples

event.target should be the button

Thanks for your help, I’m going to try that.

The examples though are just for the visual aspect of the button, there is no “event.target” there

You’ve got to dig a bit.
 
Try this to see all of the fields that come on event:

local table = {} function btnPressed( event ) print( event.phase, system.getTimer() ) for k,v in pairs( event ) do print( k, v ) end print("-------------------\n") end local btn = widget.newButton({ onPress = btnPressed })

I agree this could be clearer, but the assumption is you know about touch events already.

Anyways, my code above will dump all of the fields on the touch event so you can see what they are.

The example is for basic button creation.  Dig a bit deeper and you will find all about events here - https://docs.coronalabs.com/api/event/touch/index.html

Thanks, guys, it’s working properly now. 

It’s in the docs:

https://docs.coronalabs.com/api/library/widget/newButton.html#examples

event.target should be the button

Thanks for your help, I’m going to try that.

The examples though are just for the visual aspect of the button, there is no “event.target” there

You’ve got to dig a bit.
 
Try this to see all of the fields that come on event:

local table = {} function btnPressed( event ) print( event.phase, system.getTimer() ) for k,v in pairs( event ) do print( k, v ) end print("-------------------\n") end local btn = widget.newButton({ onPress = btnPressed })

I agree this could be clearer, but the assumption is you know about touch events already.

Anyways, my code above will dump all of the fields on the touch event so you can see what they are.

The example is for basic button creation.  Dig a bit deeper and you will find all about events here - https://docs.coronalabs.com/api/event/touch/index.html

Thanks, guys, it’s working properly now.