-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertScore.lua
executable file
·97 lines (48 loc) · 1.48 KB
/
insertScore.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
module(..., package.seeall)
local hscore
function insertScore:go(PP_params, score_value)
local sqlite = require("sqlite3")
local path = system.pathForFile("level-db.sqlite", system.DocumentsDirectory)
local file = io.open(path, "r")
local num = 0
function dbInit()
if(file==nil) then
local pathSource = system.pathForFile("level-db.sqlite", system.ResourceDirectory)
local fileSource = io.open(pathSource, "r")
local contentsSource = fileSource:read("*a")
local pathDestination = system.pathForFile("level-db.sqlite", system.DocumentsDirectory)
local fileDestination = io.open(pathDestination, "w")
fileDestination:write(contentsSource)
io.close(fileSource)
io.close(fileDestination)
num = 1
else
print("File gia' esistente!")
end
end
dbInit()
local db = sqlite.open(path)
local sql = "SELECT * FROM game WHERE level = ".. PP_params.level ..";"
local i = 0
for row in db:nrows(sql) do
i = i + 1
hscore = row.hscore
end
if (hscore == nil) then
hscore = 0
end
print("i =".. i)
if ((i ~= 0) and (hscore < score_value)) then
local sql = "UPDATE game SET hscore = ".. score_value .." WHERE level = ".. PP_params.level ..";"
db:exec(sql)
print("update: ".. sql)
end
db:close()
if (num == 0) then
io.close(file)
end
print("hscore = ")
print(hscore)
local record_value = hscore
return record_value
end