Trying to showAlert before requestExit

function Quit() native.showAlert( "", "You scored " .. score .. " !" ) native.requestExit( ) end 

Hey there,
I am currently making a quit button. When you tap it, the above code is executed.

When using the corona simulator, the message box appears and the simulator closes at the same time.

But when testing it on my Android, the game crashes and displays a “Unfortunately, <filename> has stopped”

How can I make the game to display the score message then close, without crashing ?

Any help is appriciated :slight_smile:

Joe

You are exiting before you can get the alert shown.  I would just show the alert and not call native.requestExit() yet. Instead setup a handler when they tap the okay button on the alert to delay the exit request until the user dismisses the alert.

However, I would also suggest that you re-evaluate the value of exiting the app. Most people want to keep players in their app rather than encouraging them to go do something else. Instead take them back to a menu screen or an opportunity to play the game again or restart things.

Rob

Well I hope there is an easier way to do so then using the composer library as it is quite a compicated process and my code is nearly finished so I would like to know if there was a quicker way to add the “go back to menu” functionality to the quite button

It would be hard to offer you suggestions with out knowing your code structure. If you plan on submitting this to Apple at some point, they will reject apps that exit.

Composer seems intimidating, but it’s not. My first game I didn’t understand scene managers. I had a menu function that shows the menu (in it’s own display.newGroup(). and it figured out how to get the game to end, show the menu and play a new game. It’s doable, but it is all dependent on your code.  Now that said, I can barely update that game today. It’s very fragile. I took a couple of days and migrated it and it’s much easier to maintain.

Rob

You are exiting before you can get the alert shown.  I would just show the alert and not call native.requestExit() yet. Instead setup a handler when they tap the okay button on the alert to delay the exit request until the user dismisses the alert.

However, I would also suggest that you re-evaluate the value of exiting the app. Most people want to keep players in their app rather than encouraging them to go do something else. Instead take them back to a menu screen or an opportunity to play the game again or restart things.

Rob

Well I hope there is an easier way to do so then using the composer library as it is quite a compicated process and my code is nearly finished so I would like to know if there was a quicker way to add the “go back to menu” functionality to the quite button

It would be hard to offer you suggestions with out knowing your code structure. If you plan on submitting this to Apple at some point, they will reject apps that exit.

Composer seems intimidating, but it’s not. My first game I didn’t understand scene managers. I had a menu function that shows the menu (in it’s own display.newGroup(). and it figured out how to get the game to end, show the menu and play a new game. It’s doable, but it is all dependent on your code.  Now that said, I can barely update that game today. It’s very fragile. I took a couple of days and migrated it and it’s much easier to maintain.

Rob