When I restart my game everything appears to reset back to 0 but when I increase the score for the first time again it increase by 3 instead of 1 like it is supposed to. Any suggestions on whats wrong?
This is code I have in the game part in the createScene function:
[lua]score = 0
count = 0
local timeLimit = 20
local timerHandle
timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 100)
timeLeft.x = display.contentCenterX
timeLeft.y = display.contentCenterY
timeLeft:setFillColor(0,0,0)
local function timerDown()
timeLimit = timeLimit-1
timeLeft.text = timeLimit
if(timeLimit==0)then
timer.cancel(timerHandle)
timer.alpha = 0
storyboard.gotoScene(“restart”)
storyboard.purgeScene(“game”)
end
end
timerHandle = timer.performWithDelay(1000,timerDown,-1)
function shoot(event)
if event.phase == “began” then
bullsEye.x = math.random(0, display.contentWidth - 40)
bullsEye.y = math.random(0, display.contentHeight - 100)
score = score + 1
count = count + 1
scoreText.text = score
if count == 15 then
timeLimit = timeLimit + 5
count = 0
end
end
return true
end
function endGame(event)
if event.phase == “began” then
bullsEye.alpha = 0
timeLeft.alpha = 0
timer.cancel(timerHandle)
storyboard.purgeScene(“game”)
storyboard.gotoScene(“restart”)
end
return true
end[/lua]