I have these two methods: (LF stands for love.filesystem)
Code: Select all
function loadData(file, data)
if not LF.exists(file) then return end
local RDATA = LF.read(file)
local LDATA = TSerial.unpack(RDATA)
for i,v in pairs(LDATA) do
data[i] = v
end
end
Code: Select all
function saveData(file, data)
LF.write(file, TSerial.pack(data))
end
I also have a table that defines the game's settings:
Code: Select all
config = {
sx = 1,
sy = 1,
alwaysShowCursor = false,
enableBorders = true,
keys = {
UP = 'W',
DOWN = 'S',
LEFT = 'A',
RIGHT = 'D',
QUIT = "escape"
}
I tried editing the save method so that it would delete the file and rewrite it, but that didn't work as intended, for it only deleted the file once and then never rewrote it, which caused an error when the game was opened it attempted to load the data again:
Code: Select all
function SaveManager:saveData(file, data)
if LF.exists(file) then
LF.remove(file)
end
LF.write(file, TSerial.pack(data))
end