Button Counter

I am making a pitch counter and am wondering what a counting code would look like? I can't seem to get my numbers to add and continue to add

Just put in your button function

btnClick = btnClick + 1

Something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local counter = 0
 
-- declared here so it can be referenced in button's event handler
local label
 
local button = display.newCircle( 160, 240, 40 )
button:setFillColor( 0, 255, 0 )
button:addEventListener( 'touch', function( e )
  if e.phase == 'began' then
    button:setFillColor( 255, 255, 0 )
    counter = counter + 1
    label.text = '#'..counter
  elseif e.phase == 'ended' or e.phase == 'cancelled' then
    button:setFillColor( 0, 255, 0 )
  end
end )
 
-- created here so it will appear on top of the button
label = display.newText( '#0', 0, 0, native.systemFont, 24 )
label:setTextColor( 0, 0, 0 )
label:setReferencePoint( display.CenterReferencePoint )
label.x = 160; label.y = 240

It's for a pitch counter, and I need the number to keep on being displayed

views:1921 update:2011/9/18 14:43:09
corona forums © 2003-2011