How to restart a game

How do I restart a game in one function ? When the game is over instead of going to a different screen to restart I want to stay on the same page and give the user the opportunity to touch the screen and the game restarts . Can someone help me ? 

-- This function stops the game local function endGame() -- Stop the timer timer.cancel(timerHandle) -- Iterate over 'allBalloons' table and destroy all balloons for k,v in pairs( allBalloons ) do display.remove(v) end display.newText( "Game Over", display.contentCenterX, display.contentCenterY, native.systemFont, 40 ) display.newText( "Tap to play again", 150, 300, native.systemFont, 30 ) end

-- Generic/Common enterFrame listener used by each balloon local function enterFrame( self ) -- End the Game if any balloon's CENTER falls below the bottom of the screen if( self.y \>= bottom ) then timer.cancel(timerUpTimer) endGame() end end

You will need a stopGame() function that ends the game and also a startGame() function that resets all values and objects and restarts the game

so write a start game function and at the end of 

-- Generic/Common enterFrame listener used by each balloon local function enterFrame( self ) -- End the Game if any balloon's CENTER falls below the bottom of the screen if( self.y \>= bottom ) then timer.cancel(timerUpTimer) endGame() end end

Add startGame() ?

Are you using the Composer scene management library? If so, sometimes the easiest way is to just destroy the scene entirely and start fresh, effectively restarting the scene. Of course there may be some specific things you need to manually stop or un-load before doing that, but the overall concept can work pretty well in many cases.

Brent

How do I do that ?

Did you follow through the “Star Explorer” learning project in our Getting Started guide? In particular, Chapter 5 discusses how to convert the game to Composer, and it talks about “Scene Cleanup” which outlines how to remove a scene and basically restart it. That might be the route you want to go.

https://docs.coronalabs.com/guide/programming/index.html

Brent

You will need a stopGame() function that ends the game and also a startGame() function that resets all values and objects and restarts the game

so write a start game function and at the end of 

-- Generic/Common enterFrame listener used by each balloon local function enterFrame( self ) -- End the Game if any balloon's CENTER falls below the bottom of the screen if( self.y \>= bottom ) then timer.cancel(timerUpTimer) endGame() end end

Add startGame() ?

Are you using the Composer scene management library? If so, sometimes the easiest way is to just destroy the scene entirely and start fresh, effectively restarting the scene. Of course there may be some specific things you need to manually stop or un-load before doing that, but the overall concept can work pretty well in many cases.

Brent

How do I do that ?

Did you follow through the “Star Explorer” learning project in our Getting Started guide? In particular, Chapter 5 discusses how to convert the game to Composer, and it talks about “Scene Cleanup” which outlines how to remove a scene and basically restart it. That might be the route you want to go.

https://docs.coronalabs.com/guide/programming/index.html

Brent