Button Help!

How can i display on the screen the number of times i touched a button!!

One way would be to make a variable called ‘numTouches’ for example, and set it equal to 0
Then in your touch code increase the touch count by 1 ( numTouches = numTouches + 1 ) and then just print it however you want.
http://docs.coronalabs.com/api/library/string/format.html

**local numTouchesText = display.newText( " ", display.contentWidth/2, display.contentHeight/2, native.systemFont, 14 )

numTouchesText.text = ( "Number of touches: " … tostring( numTouches )**
)

Cheers!

-Saer

when i touch the button:

error: …main.lua4: attempt to index global ‘event’ (a nil value)

  local numTouches = 0   local function numTouches (e)   if event.phase == "began" then       numTouches = numTouches+1         end  end       local button = display.newRect(0,0, 100, 100) button:addEventListener("touch", numTouches)            numTouchesText = display.newText("", display.contentWidth/2, display.contentHeight/2, native.sistemFont, 14)     numTouchesText.text=("Number of Touches".. tostring(numTouches)  

Error says everything. In line 4 you try to access variable ‘event’ which is nowhere to find. You have ‘e’ as argument for listener function, not ‘event’. So you must check for e.phase value.

One way would be to make a variable called ‘numTouches’ for example, and set it equal to 0
Then in your touch code increase the touch count by 1 ( numTouches = numTouches + 1 ) and then just print it however you want.
http://docs.coronalabs.com/api/library/string/format.html

**local numTouchesText = display.newText( " ", display.contentWidth/2, display.contentHeight/2, native.systemFont, 14 )

numTouchesText.text = ( "Number of touches: " … tostring( numTouches )**
)

Cheers!

-Saer

when i touch the button:

error: …main.lua4: attempt to index global ‘event’ (a nil value)

  local numTouches = 0   local function numTouches (e)   if event.phase == "began" then       numTouches = numTouches+1         end  end       local button = display.newRect(0,0, 100, 100) button:addEventListener("touch", numTouches)            numTouchesText = display.newText("", display.contentWidth/2, display.contentHeight/2, native.sistemFont, 14)     numTouchesText.text=("Number of Touches".. tostring(numTouches)  

Error says everything. In line 4 you try to access variable ‘event’ which is nowhere to find. You have ‘e’ as argument for listener function, not ‘event’. So you must check for e.phase value.