Button Counter

I am making a pitch counter and I am having trouble making it so when I press a button it adds up. Can anyone help?

strikes = 0
balls = 0
totalpitches = 0

local ui= require ("ui")

--Background
background = display.newImage("boston-fenway-park-sunset.jpeg", true)

--Total wording
local total = display.newRoundedRect( 50, 22, 225, 175, 8)
total: setFillColor (black)

local t = ui.newLabel{
bounds = { 50, 22, 225, 175, 8 },
text = "Total Pitches",
font = "AmericanTypewriter-Bold",
textColor = { 255, 255, 255, 255 },
size = 30,
align= "center",
}

-- Total pitches number
local totalp = display.newRoundedRect( 110, 65, 100, 100, 8)
totalp: setFillColor (black)

local tp = ui.newLabel{
bounds = { 110, 5, 100, 100, 8},
text = tostring ( totalpitches ),
font = "AmericanTypewriter-Bold",
textColor = { 255, 255, 255, 255 },
size = 145,
align= "center",
}

-- Strike wording
local strike = display.newRoundedRect( 20, 195, 125, 125, 8)
strike: setFillColor (250,0 ,0)

local s = ui.newLabel{
bounds = { 20, 195, 125, 125, 8},
text = "Strikes",
font = "AmericanTypewriter-Bold",
textColor = { 255, 255, 255, 255 },
size = 28,
align= "center",
}

-- Strike number
local totals = display.newRoundedRect( 40, 235, 82, 82, 8)
totals: setFillColor (255, 0,0)

local ts = ui.newLabel{
bounds = { 45, 185, 82, 82, 8},
text = tostring ( strikes ),
font = "AmericanTypewriter-Bold",
textColor = { 255, 255, 255, 255 },
size = 100,
align= "center",
}

-- Strike Button
local button1Press = function( event )
s:setText( "+1" )
t:setText( "+1" )
end

local button1Release = function( event )
s:setText( "Strikes" )
t:setText( "Total Pitches" )

end

local buttonHandler = function( event )
s:setText( "id = " .. event.id .. ", phase = " .. event.phase )
t:setText( "id = " .. event.id .. ", phase = " .. event.phase )
end

local button1 = ui.newButton{
default = "buttonRed.png",
over = "buttonRedOver.png",
onPress = button1Press,
onRelease = button1Release,
text = "Strike",
size= 36,
emboss = true }
button1.x= 160; button1.y= 360

-- Ball wording
local ball= display.newRoundedRect( 175, 195, 125, 125, 8)
ball: setFillColor (0, 255,0)

local b = ui.newLabel{
bounds = { 175, 195, 125, 125, 8 },
text = "Balls",
font = "AmericanTypewriter-Bold",
textColor = { 255, 255, 255, 255 },
size = 28,
align = "center"}

-- Ball Number
local totalb = display.newRoundedRect( 175, 235, 82, 82, 8)
totalb: setFillColor (0,255,0)

local tb = ui.newLabel{
bounds = {200, 185, 82, 82, 8},
text = tostring ( balls ),
font = "AmericanTypewriter-Bold",
textColor = { 255, 255, 255, 255 },
size = 100,
align= "center",
}

-- Ball Button
local button2Press = function( event )
b:setText( "+1" )
t:setText( "+1" )
balls = balls + 1
totalpitches = totalpitches + 1
end

local button2Release = function( event )
b:setText( "Balls" )
t:setText( "Total Pitches" )
end

local buttonHandler = function( event )
b:setText( "id = " .. event.id .. ", phase = " .. event.phase )
t:setText( "id = " .. event.id .. ", phase = " .. event.phase )
end

local button2 = ui.newButton{
default = "buttonGreen.png",
over = "buttonGreenOver.png",
onPress = button2Press,
onRelease = button2Release,
text = "Ball",
size= 36,
emboss = true }
button2.x = 160; button2.y = 425

-- Strike Delete Button
local button4Press = function( event )
s:setText( "-1" )
t:setText( "-1" )
end

local button4Release = function( event )
s:setText( "Strikes" )
t:setText( "Total Pitches" )
end

local buttonHandler = function( event )
s:setText( "id = " .. event.id .. ", phase = " .. event.phase )
t:setText( "id = " .. event.id .. ", phase = " .. event.phase )
end

local button4= ui.newButton{
default= "delete_criterion_down.tif",
over = "delete_criterion_disabled.tif",
onPress = button4Press,
onRelease = button4Release,
emboss = true
}
button4.x = 135; button4.y = 310

-- Ball Delete Button
local button3Press = function( event )
b:setText( "-1" )
t:setText( "-1" )
end

local button3Release = function( event )
b:setText( "Balls" )
t:setText( "Total Pitches" )
end

local buttonHandler = function( event )
b:setText( "id = " .. event.id .. ", phase = " .. event.phase )
t:setText( "id = " .. event.id .. ", phase = " .. event.phase )
end

local button3= ui.newButton{
default= "delete_criterion_down.tif",
over = "delete_criterion_disabled.tif",
onPress = button3Press,
onRelease = button3Release,
emboss = true
}
button3.x = 290; button3.y = 310

-- Back to Homepage
local button5= ui.newButton{
default= "buttonArrow.png",
over= "buttonArrowOver.png",
onPress = button5Press,
onRelease= button5Release,
emboss = true
}
button5.x = 25; button5.y = 40

views:1537 update:2011/9/21 9:18:04
corona forums © 2003-2011