我正在创建一个游戏,完成后将其存储在数据库中(下面的代码添加了它)
-- open SQLite database, if it doesn't exist, create database
local path = system.pathForFile("leaderboards.sqlite", system.DocumentsDirectory)
db = sqlite3.open( path )
print(path)
-- setup the table if it doesn't exist
local tablesetup = "CREATE TABLE IF NOT EXISTS leaderboards (id INTEGER PRIMARY KEY, score INDEXED);"
db:exec( tablesetup )
print(tablesetup)
-- save student data to database
local tablefill = "INSERT INTO leaderboards VALUES (NULL,'" .. score .. "');"
print(tablefill)
db:exec( tablefill )
-- close database
db:close()
print("db closed")
然后我想在屏幕顶部显示最高分所以这是我的显示功能
local function highScore()
-- open database
local path = system.pathForFile("leaderboards.sqlite", system.DocumentsDirectory)
db = sqlite3.open( path )
print(path)
--print all the table contents
local sql = "SELECT MAX(score) FROM leaderboards"
local val = db:exec(sql)
local t = display.newText("Best: "..val, 300, -20, nil, 28)
print(val)
t:setTextColor(255,255,255)
db:close()
end
现在在屏幕上它只是说 0 而不是高分或任何屏幕。这些值正在数据库中输入,但我的 sql 语句没有显示它。