How to reload / restart app from within main.lua ?

Hi,

I am writing a very linear app. When the app has completed running, I give an option to the user to restart the app, and play again. Currently, when the touch event for the button is triggered, the main() function is called again. Whilst this works, it is not useable in a final app as there are a number of performance issues.

I could not see anything in the documentation, but was wondering if there is a safe way to restart/reload an app, from within the app itself. The desired behavior would be akin to clicking reload on a web browser, or triggering the same using javascript.

Thanks for your help.
Richard.
[import]uid: 7290 topic_id: 1506 reply_id: 301506[/import]

There is sample code in our code section under the game “Samurai Kitchen”

You may want to start there.

http://developer.anscamobile.com/content/additional-samples#Samurai_Kitchen_game

Carlos [import]uid: 24 topic_id: 1506 reply_id: 4232[/import]

Hello and thank you for your reply. I just followed your link and I can not find any Samurai Kitchen. can you help me with another sample code to restart my app [import]uid: 61526 topic_id: 1506 reply_id: 40861[/import]

what i find convenient is:

create screens, objects, listeners and all interactivity.
once. this is important.
forward declarations are necessary

create an initialize function that:
destroys running timers and objects from previous play
resets variables (time, flags, score etc)
resets display objects (position, visibility, etc)
restarts timers

to restart the app, i call initialize
[import]uid: 6459 topic_id: 1506 reply_id: 40910[/import]

My basic logic is to create a StartGame function that sets all the initial variables. Then I construct the game in the main.lua chunk at the bottom. This loads the background and UI elements. Then when main.lua ends, the last call into my menu() function which loads a screen over top of the game. When the New Game button is selected, the menu destroys itself and calls the StartGame function. [import]uid: 19626 topic_id: 1506 reply_id: 40924[/import]

Thanks tetu & robmiracle. I was able to apply your suggestions and its working great!! Thanks Again! :slight_smile: [import]uid: 61526 topic_id: 1506 reply_id: 41373[/import]

If you are working on a game or app you might want to consider using the Director class. It is very nice and works great when it comes to this kind of stuff [import]uid: 22737 topic_id: 1506 reply_id: 41390[/import]