TheGame scene for gamOver automatically going to main.lua

I have the following situation: 
 
main.luamainMenu.luatheGame.luahowTwoPlay.lua  and  gameOver.lua 
 
The game is going well, until arriving at the scene of game over. In the scene thegame I add one point to each tap on a square, when the user loses the game goes to the game over screen where you want to display the point from the last move and the maximum score achieved. I can now record the score in the database normally, but when the scene will TheGame for gamOver is automatically going to main.lua, the game remains in the game over screen, it restarts, or something. I realized that when the line of retreat insert in sqlite does not happen, then the problem is there. 
 
Follows the code of the page  gameOver.lua

local sqlite3 = require( "sqlite3" ) local path = system.pathForFile("data.db", system.ResourceDirectory) -- DocumentDirectory local db = sqlite3.open(path) local function onSystemEvent(event) &nbsp;&nbsp;&nbsp;&nbsp;if event.type == "applicationExit" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if db and db:isopen() then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db:close() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end end -- Cria tabela local tableSetup = "CREATE TABLE IF NOT EXISTS score (points CHAR(5));" db:exec(tableSetup) local composer = require( "composer" ) local scene = composer.newScene() -- Dimensões do dispositivo e centro do mesmo local w = display.contentWidth local h = display.contentHeight local centerX = w \* 0.5 local centerY = h \* 0.5 -- Touch event listener local function onSceneTouch( self, event ) &nbsp;&nbsp;&nbsp;&nbsp;local objectName = event.target.name &nbsp;&nbsp;&nbsp;&nbsp;local currScene = composer.getSceneName( "current" ) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(objectName == 'playAgainButton') then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;composer.removeScene(currScene) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;composer.gotoScene( "theGame", "fade", 300 ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(objectName == 'backMenu') then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;composer.removeScene(currScene) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;composer.gotoScene( "mainMenu", "fade", 300 ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;end end -- "scene:create()" function scene:create( event ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;local sceneGroup = self.view &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;-- Texto de pontuação &nbsp;&nbsp;&nbsp;&nbsp;local params = event.params -- variavel passada da cena theGame &nbsp;&nbsp;&nbsp;&nbsp;local score = display.newText(params.currentScore, centerX, centerY/2, native.systemFont, 36 )&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;sceneGroup:insert( score ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;-- Exibe a mensagem de game over e as outras opções &nbsp;&nbsp;&nbsp;&nbsp;gameOverAlert = display.newText("Game Over!", centerX, centerY, native.systemFont, 26 ) &nbsp;&nbsp;&nbsp;&nbsp;gameOverAlert:setFillColor( 255,0,0 ) &nbsp;&nbsp;&nbsp;&nbsp;sceneGroup:insert( gameOverAlert ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;playAgainButton = display.newText("Play Again", centerX, centerY\*1.2, native.systemFont, 36 ) &nbsp;&nbsp;&nbsp;&nbsp;playAgainButton:setFillColor( 0,255,0 ) &nbsp;&nbsp;&nbsp;&nbsp;playAgainButton.name = 'playAgainButton' &nbsp;&nbsp;&nbsp;&nbsp;playAgainButton.touch = onSceneTouch &nbsp;&nbsp;&nbsp;&nbsp;sceneGroup:insert( playAgainButton ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;local backMenu = display.newText("\< Voltar ao menu", centerX, centerY\*2, native.systemFont, 26 ) &nbsp;&nbsp;&nbsp;&nbsp;backMenu.name = 'backMenu' &nbsp;&nbsp;&nbsp;&nbsp;backMenu:setFillColor( 255,255,255 ) &nbsp;&nbsp;&nbsp;&nbsp;backMenu.touch = onSceneTouch &nbsp;&nbsp;&nbsp;&nbsp;sceneGroup:insert( backMenu ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;playAgainButton:addEventListener( "touch", playAgainButton ) &nbsp;&nbsp;&nbsp;&nbsp;backMenu:addEventListener( "touch", backMenu ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;insertQuery = "INSERT INTO score (points) VALUES ("..score.text..");"; db:exec(insertQuery) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) --------------------------------------------------------------------------------- Runtime:addEventListener("system", onSystemEvent) return scene

Sorry my english, english is not my native language

I guess you are missing single quotes for char field in your insert query.

Hi danstrmecki, the data are being entered correctly, the problem is that when inserted the scene “jumps” to the home screen, does not stand still in the game over screen.

I put an example to facilitate understanding of my problem here -> http://forums.coronalabs.com/topic/50075-problem-when-saving-to-txt-using-exchange-scenes/

I guess you are missing single quotes for char field in your insert query.

Hi danstrmecki, the data are being entered correctly, the problem is that when inserted the scene “jumps” to the home screen, does not stand still in the game over screen.

I put an example to facilitate understanding of my problem here -> http://forums.coronalabs.com/topic/50075-problem-when-saving-to-txt-using-exchange-scenes/

In your game over function when you call other other scenes based on which button the user clicks, you are using two if statements when one of them should be an else statement. 

main.lua should not be a composer scene.  Its an initialization file and a jumping point into composer scenes

Rob

In your game over function when you call other other scenes based on which button the user clicks, you are using two if statements when one of them should be an else statement. 

main.lua should not be a composer scene.  Its an initialization file and a jumping point into composer scenes

Rob