I have the following situation:
main.lua , mainMenu.lua , theGame.lua , howTwoPlay.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) if event.type == "applicationExit" then if db and db:isopen() then db:close() end 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 ) local objectName = event.target.name local currScene = composer.getSceneName( "current" ) if event.phase == "began" then if(objectName == 'playAgainButton') then composer.removeScene(currScene) composer.gotoScene( "theGame", "fade", 300 ) end if(objectName == 'backMenu') then composer.removeScene(currScene) composer.gotoScene( "mainMenu", "fade", 300 ) end return true end end -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Texto de pontuação local params = event.params -- variavel passada da cena theGame local score = display.newText(params.currentScore, centerX, centerY/2, native.systemFont, 36 ) sceneGroup:insert( score ) -- Exibe a mensagem de game over e as outras opções gameOverAlert = display.newText("Game Over!", centerX, centerY, native.systemFont, 26 ) gameOverAlert:setFillColor( 255,0,0 ) sceneGroup:insert( gameOverAlert ) playAgainButton = display.newText("Play Again", centerX, centerY\*1.2, native.systemFont, 36 ) playAgainButton:setFillColor( 0,255,0 ) playAgainButton.name = 'playAgainButton' playAgainButton.touch = onSceneTouch sceneGroup:insert( playAgainButton ) local backMenu = display.newText("\< Voltar ao menu", centerX, centerY\*2, native.systemFont, 26 ) backMenu.name = 'backMenu' backMenu:setFillColor( 255,255,255 ) backMenu.touch = onSceneTouch sceneGroup:insert( backMenu ) playAgainButton:addEventListener( "touch", playAgainButton ) backMenu:addEventListener( "touch", backMenu ) 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