Problem with Timer and cancel

Hi everyone…

I will do my best to explain this problem…

I have a button that plays a sound. tap on the button and it plays the song

I have another button to go to another scene, like home button, I tap on that and goes home.

Here is the problem

When I first relaunch the app or go to that scene the first time

I see the play and home buttons

If I tap on the play FIRST, the song plays, and the home button works fine!

but if I tap on the home first, I get this ERROR

Attemp to index a nil value

stack traceback:
    ?: in function ‘cancel’
    cTiny.lua:305: in function <cTiny.lua:301>
    ?: in function ‘dispatchEvent’
    ?: in function ‘?’
    ?: in function ‘gotoScene’
    cTiny.lua:293: in function <cTiny.lua:292>
    ?: in function <?:218>

– So I have to hide the home first, so users can only see the play button

so they have only one choice, when they tap on that

then I make a transition to show the home button, because by now, the home button works fine.

But I would like to have both buttons visible all the time

I just don’t know why it doesn’t work the first time.

Thanks for all your help

Check to see if your timer object is nil before trying to cancel it :wink:

For example:

if myTimer ~= nil then timer.cancel( myTimer ) end

thank you very much, that works really nice!

Thanks

Check to see if your timer object is nil before trying to cancel it :wink:

For example:

if myTimer ~= nil then timer.cancel( myTimer ) end

thank you very much, that works really nice!

Thanks