How to Reset app?

Hi All
Forgive me if I’m missing something obvious but how to I reset my app as if it had been relaunched ?

there must be an easier way than resetting all the variables, repositioning all pictures etc
Thanks
Alex

[import]uid: 66618 topic_id: 22493 reply_id: 322493[/import]

@ alexsmith944

Not sure I understand exactly what you are looking for, do you mean like a “Retry” button or Reset as in exit the app and when you go back in it starts all over again ( Launch image > Title > ect) If its exiting the app and going back in from the beginning then just dont add UIApplicationExitsOnSuspend = false on your build.settings And if its a “Retry” Button it can be done different ways. Here are 2 Examples:

1: If using Director Class create a file can be called anything and when you hit retry then director change scene to the file you created and on that file send yourself back to the level you were currently playing. Makes Sense? Something Like Level1.lua > Retry button pressed > Level1X.lua > level1.lua

2: Depending on your game structure you can reposition where objects should be or more like were when the level starts. [import]uid: 30314 topic_id: 22493 reply_id: 89696[/import]

Scenes are definitely the way to accomplish this. Using Storyboard, you’d purge your game scene every time you returned to the menu. Like this, for example:

function scene:enterScene(event)  
 storyboard.purgeScene("game")  
end  

Then in you game scene, put all your object creation, initializations, and variable resets into the createScene function.

If you want on relaunch specifically, then add a listener that switches the scene as necessary and purges the game scene on each resume. This isn’t usually the best way to go though, per se.

[code]
local function onAppState(event)
if (event.type == “applicationResume”) then
storyboard.gotoScene(“menu”)
storyboard.purgeScene(“game”)
end
end

Runtime:addEventListener(“system”, onAppState)
[/code] [import]uid: 87138 topic_id: 22493 reply_id: 89712[/import]

Hi,
Thanks for your input.
I basically want to implement the equivalent of a Command-R in the simulator.

I’m not using director or scenes, just a simple app that takes a photo, does some stupid stuff to it, then saves the screenshot to the photo library.
I’d like to give the user the option to take another, but it involves deleting the photos, repositioning a bunch of shapes and all sorts.

Thanks Revaerie, sounds like my best bet is to integrate this into a scene a use that route.

All the best
Alex [import]uid: 66618 topic_id: 22493 reply_id: 89761[/import]