Alert popup doesn't appear more than twice

Hi, I can’t understand why the alert popup doesn’t appear more than twice. It appear the first time, then when I press “Riprova” it appears again, but if I press “Riprova” for the second time it doesn’t appear anymore.

Here the code:

function connection() local status = network.getConnectionStatus() if status.isConnected then gameNetworkSetup() if detect == "classifica" then postScoreSubmit() gameNetwork.show("leaderboards") elseif detect == "trofei" then gameNetwork.show("achievements") end else connectionAlert = native.showAlert("Errore di connessione", "Non è stata rilevata alcuna connessione a Internet.", {"Annulla", "Riprova"}, fConnectionAlert) end end function fConnectionAlert(event) if "clicked" == event.action then local i = event.index if 1 == i then native.cancelAlert(connectionAlert) elseif 2 == i then connection() end end end

I know that you can’t have 2 on the screen at the same time. In your fConnectionAlert function you dismiss the popup manually if they choose option 1, but not if they choose option 2.  

I would suggest trying this:

if 1 == i then native.cancelAlert(connectionAlert) elseif 2 == i then native.cancelAlert(connectionAlert) timer.performWithDelay(100, connection, 1) end

This will will clear the existing alert view, and then wait 100 ms (just to make sure the alert view is fully removed) before calling another one.

Thank you, good advice! :slight_smile:

I know that you can’t have 2 on the screen at the same time. In your fConnectionAlert function you dismiss the popup manually if they choose option 1, but not if they choose option 2.  

I would suggest trying this:

if 1 == i then native.cancelAlert(connectionAlert) elseif 2 == i then native.cancelAlert(connectionAlert) timer.performWithDelay(100, connection, 1) end

This will will clear the existing alert view, and then wait 100 ms (just to make sure the alert view is fully removed) before calling another one.

Thank you, good advice! :slight_smile: