Hi there. I'm having some trouble saving data to the disk and I thought I may be approaching it the wrong way.
I have a function that is basically this:
Code: Select all
local data = [[This no more than 700 kb, written using string.char() concatenations and it includes zeroes]]
local f, e = love.filesystem.newFile("universe.bin")
if e or not f then error(e) end
if not f:open("w") then error("Could not open file for writing") end
if not f:write(data) then error("Could not write to file") end
f:close()
The problem I have is that the code runs with no errors and I can't find universe.bin anywhere. I'm using Windows 7 64 bit and Löve 0.9.0. I have looked in %appdata% (Local and Roaming), the documents folder, the user folder and the source code folder. The fact that I'm getting no errors makes me think I did not understand what I read on the wiki. Is there anything obvious I'm missing? Is the coroutine a problem? Nightly Löve bug?
Thank you!
Full code involved:
Code: Select all
StateSaveUniverse = {}
function StateSaveUniverse.load(data)
setmetatable(StateSaveUniverse, {__index = State})
StateSaveUniverse.nextState = data or StateMenu
StateSaveUniverse.coro = coroutine.create(StateSaveUniverse.doSave)
end
function StateSaveUniverse.update(dt)
if coroutine.status(StateSaveUniverse.coro) == "suspended" then
coroutine.resume(StateSaveUniverse.coro)
elseif coroutine.status(StateSaveUniverse.coro) == "dead" then
Game:ChangeState(StateSaveUniverse.nextState)
end
end
function StateSaveUniverse.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.printf("Saving game...", 0, love.graphics.getHeight()/4 - 12, love.graphics.getWidth()/2, "center")
end
function StateSaveUniverse.doSave()
local data = ""
for i,v in ipairs(StateGame.universe.sectors) do
data = data.."S"
for ii,vv in ipairs(v) do
data = data.."s"
local star = vv:serialize()
data = data..string.char(star[1])
data = data..string.char(star[2])
data = data..string.char(star[3])
for iii,vvv in ipairs(vv.planets) do
data = data.."p"
data = data..StateSaveUniverse.serializeShort(vvv[1])
data = data..StateSaveUniverse.serializeShort(vvv[2])
data = data..StateSaveUniverse.serializeShort(vvv[3])
data = data..StateSaveUniverse.serializeShort(vvv[4])
data = data..StateSaveUniverse.serializeFloat(vvv[5])
data = data..StateSaveUniverse.serializeShort(vvv[6])
data = data..StateSaveUniverse.serializeFloat(vvv[7])
data = data..StateSaveUniverse.serializeFloat(vvv[8])
data = data..StateSaveUniverse.serializeShort(vvv[9])
data = data..StateSaveUniverse.serializeShort(vvv[10])
for m=1,vvv[9] do
data = data..StateSaveUniverse.serializeFloat(vvv[10+m])
end
for a=1,vvv[10] do
data = data..StateSaveUniverse.serializeFloat(vvv[10+vvv[9]+a])
end
end
end
end
local f, e = love.filesystem.newFile("universe.bin")
if e or not f then error(e) end
if not f:open("w") then error("Could not open file for writing") end
if not f:write(data) then error("Could not write to file") end
f:close()
end
function StateSaveUniverse.serializeShort(n)
return string.char(math.floor((n+32767)/256))..string.char(n - math.floor((n+32767)/256))
end
function StateSaveUniverse.serializeFloat(n)
return string.char(StateSaveUniverse.serializeShort(math.floor(n)))..string.char(StateSaveUniverse.serializeShort(math.floor(n*100000)))
end