-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataControl.lua
More file actions
52 lines (43 loc) · 1.42 KB
/
dataControl.lua
File metadata and controls
52 lines (43 loc) · 1.42 KB
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
dataControl = {}
--savefile should be in the registry
saveFile,fileError = fs.newFile("data81.txt")
function dataControl.draw()
if DEBUG_MODE then
love.graphics.setColor(0,255,0)
local y = 30
for name,data in pairs(rawData) do
love.graphics.print(name..": "..tostring(data),0,y)
y=y+30
end
end
end
function dataControl.save()
local data = {}
--allocate variables to the data object here, that will be saved
data.scoreboard = scoreboard
--end variable alloation
if saveFile:open("w") then
saveFile:write(serialize(data))
saveFile:close()
end
end
function dataControl.load()
if saveFile:open("r") then
local rawData = saveFile:read()
local data = deserialize(rawData)
if type(data)=='table' then
--allocate variables to load and where to assign them
--where numbers are required use tonumber!! else BUGS
scoreboard = {}
for i,v in ipairs(data.scoreboard) do
if tonumber(v.score) > 0 then
table.insert(scoreboard,{score=math.floor(tonumber(v.score)) or 0,powerups=tonumber(v.powerups) or 0,kills=tonumber(v.kills) or 0})
end
end
rawData = data -- for debug info
--end variable allocation
end
saveFile:close()
end
end
return dataControl