Hi! I’m new at this and I’m trying to learn this stuff.
I’m coding a database to store the highscores and time at each lvl of the game.
The table and the set of initial data is all Ok. My problem is when updating the highscores.
Here is all sql commands used:
[lua]require(“sqlite3”)
local path = system.pathForFile(“ballsvssquaresDB.db”, system.DocumentsDirectory)
local db = sqlite3.open(path)
– does the obvious…
local sql=[[
CREATE TABLE IF NOT EXISTS highscores (id INTEGER PRIMARY KEY, highscore, time);
]]
db:exec(sql)
–Should be used only once, when game is first time started, to fill te database.
function setTable()
db:exec(“DELETE FROM highscores”) --when coding, database should be deleted, otherwise would grow whenever I debug it
for id=1,99 do
local sql = [[
INSERT INTO highscores VALUES(NULL,0,0);
]]
db:exec(sql)
end
end
– Used to reset highscores
function resetTable()
local sql = [[
UPDATE highscores SET highscore=0, time=0;
]]
db:exec(sql)
end
– Retrieve a highscore from a given lvl
function whatHighScore(lvl)
local sql = [[
SELECT highscore FROM highscores WHERE id=]]…lvl…[[ LIMIT 1;
]]
local tumblr = db:exec(sql)
return tumblr
end
– When a new highscore is accomplished, should be updates
function updateHighScore(lvl,myScore,timeGame)
local sql = [[
UPDATE highscores SET highscore = ]]…myScore…[[, time =]]…timeGame…[[WHERE id =]]…lvl…[[;
]]
db:exec(sql)
print(whatHighScore(lvl),lvl,myScore,timeGame,sql) --debug stuff
end[/lua]
The problem is, it is NOT updating! What am I doing wrong!?
Thanks in advance, regis.
PS: If it matters, I use SDK on windows and build for android (nexus s, android 2.3)
[import]uid: 41756 topic_id: 10247 reply_id: 310247[/import]