0
votes

I have a back button in my game. It has a click event called btnTap. On click it gives an alert where the user is given two options, to go to "luduMenu" scene or to keep playing. But its not working, the scene still remains the same when I click yes. Heres the code I tried.

local onComplete = function ( event )
  if "clicked" == event.action then
    local i = event.index
    if 1 == i then
        -- Do nothing; dialog will simply dismiss
        system.setIdleTimer( true )
        storyboard.gotoScene (  "luduMenu" )

    elseif 2 == i then
        -- Open URL if "Learn More" (the 2nd button) was clicked

    end
  end
end

-- local forward references should go here --
local function btnTap(event)
  local alert1 = native.showAlert( "Go Back", "Are you sure?", { "Yes", "No" }, onComplete )
  return true
end
1

1 Answers

0
votes

I solved the problem by removing the line

storyboard.purgeScene("onevsone")

from the exitscene event of the scene and arranging the code like below

local function btnTap(event)
    local function onAlertComplete(event)
      if "clicked" == event.action then
        local i = event.index
        if i == 1 then
            storyboard.gotoScene("luduMenu")
        end
      end
    end

    native.showAlert( "End Game?", "Are you sure you want to exit this game?", { "Yes", "No" }, onAlertComplete )
    return true
end