I am using database to keep the highscore record. On storyboard scene change i make file to display highscore. I make database first, then table, then retrieve the record. Check if now made score is more than the existing in database. Update the first existing record.
Its working perfectly fine on the simulator, but on device it stucks on the previous scene and never changes the scene to the highscore file.
It was changing scene before database was implemented.
--Include sqlite require "sqlite3" local path = system.pathForFile("myDataBaseASDF.db", system.DocumentsDirectory) db = sqlite3.open( path ) local tablesetup = [[CREATE TABLE IF NOT EXISTS highScoreClassic (id INTEGER PRIMARY KEY, Time, Taps);]] print(tablesetup) db:exec( tablesetup ) local dbRows = 0 local dbTaps = 0 local dbTime = "00:00:00" for row in db:nrows("SELECT \* FROM highScoreClassic WHERE id=1;") do --print( "Row " .. row.id, row.Taps, row.Time ) dbRows = dbRows + 1 dbTaps = row.Taps dbTime = row.Time end function isHighscore() if myData.currentScore \> dbTime then return true elseif myData.currentScore == dbTime and myData.taps \> dbTaps then return true elseif myData.currentScore == dbTime and myData.taps \< dbTaps then return false else return false end end function saveToDataBase() print("updating") local q = [[UPDATE highScoreClassic SET Time=']]..myData.currentScore..[[', Taps=]]..myData.taps..[[WHERE id=1;]] db:exec( q ) end function saveToDataBaseFirstTime() print("inserting") local tablefill =[[INSERT INTO highScoreClassic VALUES (NULL, ']]..myData.currentScore..[[',']]..myData.taps..[[');]] db:exec( tablefill ) end if ( dbRows \> 0 ) then if ( isHighscore() ) then print(dbTime, dbTaps) note = display.newText( "Congratulations !!!\nNew High Score\n" .. "Time: " .. myData.currentScore .. "\nTaps: " .. myData.taps, 10 , display.contentHeight/2, "Harrowprint", 42) saveToDataBase() else note = display.newText( "Time: " .. myData.currentScore .. "\nTaps: " .. myData.taps, 10 , display.contentHeight/2, "Harrowprint", 42) end else note = display.newText( "Congratulations !!!\nNew High Score\n" .. "Time: " .. myData.currentScore .. "\nTaps: " .. myData.taps, 10 , display.contentHeight/2, "Harrowprint", 42) saveToDataBaseFirstTime() print("firsTime") end