Object 如果我想根据分数的增加取消计时器,我需要写什么?(电晕)

Object 如果我想根据分数的增加取消计时器,我需要写什么?(电晕),object,if-statement,timer,lua,coronasdk,Object,If Statement,Timer,Lua,Coronasdk,当玩家选择正确的角色时,我试图取消计时器。我得出的结论是,两种可能的方法是根据分数的增加或addEventListener的初始化来取消计时器。我曾试图胡乱摆弄一些可能的选择,但没有一个奏效。有没有关于写什么使条件可行的想法,以便计时器根据此类事件的发生而取消?以下是迄今为止我掌握的代码: function timeClock(event) if event.time > 2000 then storyboard.gotoScene( "restartEasy" ) randomImage

当玩家选择正确的角色时,我试图取消计时器。我得出的结论是,两种可能的方法是根据分数的增加或addEventListener的初始化来取消计时器。我曾试图胡乱摆弄一些可能的选择,但没有一个奏效。有没有关于写什么使条件可行的想法,以便计时器根据此类事件的发生而取消?以下是迄今为止我掌握的代码:

function timeClock(event)
if event.time > 2000 then
storyboard.gotoScene( "restartEasy" )
randomImage.alpha = 0
else
timer.cancel( event.source ) 
end
end

function endGame(event)
if imageFile == "redbox.png" then
timer.performWithDelay( 2000, timeClock )
randomImage.alpha = 0
mydata.score = mydata.score + 1
scoreText.text = mydata.score
button1.x = math.random( 55, 300)
button1.y = math.random( 55, 300)
button2.x = math.random( 55, 300)
button2.y = math.random( 55, 300)
imageFile = imageFiles[math.random(2)]
randomImage = display.newImage(imageFile, centerX, screenTop + 20)
storyboard.gotoScene( "restartEasy" )
randomImage.alpha = 0

end
end

function endGame2(event)
if imageFile == "bluebox.png" then
timer.performWithDelay( 2000, timeClock )
randomImage.alpha = 0
mydata.score = mydata.score + 1
scoreText.text = mydata.score
button1.x = math.random( 55, 300)
button1.y = math.random( 55, 300)
button2.x = math.random( 55, 300)
button2.y = math.random( 55, 300)
imageFile = imageFiles[math.random(2)]
randomImage = display.newImage(imageFile, centerX, screenTop + 20)
else
storyboard.gotoScene( "restartEasy" )
randomImage.alpha = 0

end
end

button1:addEventListener("touch", endGame)
button2:addEventListener("touch", endGame2)

end

例如,将计时器命名为公共变量

timer1 = timer.performWithDelay(2000, timeClock)
然后在函数中使用取消计时器

timer.cancel(timer1)

如果有人需要了解更多信息来帮助,请告诉我!谢谢你的帮助。然而,计时器本身并不是问题,因为您建议它的方式没有改变任何东西。因此,条件必须是问题所在。万一你忘了我想完成什么,我希望计时器根据分数的变化而结束,但问题是,我不知道如何将其作为一个条件来写。有什么想法吗?