Hi all,
I was wondering if it was a good idea to show an alert from within a button handler.
Basically, I have a “play level” button. In the button handler I check if the player has enough coins to play this level. If yes then I deduct the coins and goto the level.
But if the user doen’t have enough coins, which of the following is better?
local function handleButtonEvent( event ) if ( "ended" == event.phase ) then if (event.target.id == "play\_level\_btn") then if coins \> 0 then coins = coins - 1 composer.gotoScene( "play\_level",scene\_options) else native.showAlert("Warning", "You don't have enough coins!", { "OK", alertListener}) end end end return true end
Or (only line number 8 is changed)
local function handleButtonEvent( event ) if ( "ended" == event.phase ) then if (event.target.id == "play\_level\_btn") then if coins \> 0 then coins = coins - 1 composer.gotoScene( "play\_level",scene\_options) else timer.performWithDelay( 100, showCoinsAlert) end end end return true end
Thanks for your help.