Hi all!
I've been trying to get a save file system working and I've got to the point where I can write the savefile.txt as well as the data I'd like within it. Now I'm trying to read the data I've written on startup to apply the savefile changes. I am stuck trying to figure out how to use Stream:Seek() and Stream:ReadLine() to do this.
Here is what my code currently looks like:
savefile=FileSystem:ReadFile("snowboardingsavefile.txt")
--create savefile if it doesnt exist
if savefile==nil then
savefile = FileSystem:WriteFile("snowboardingsavefile.txt")
--setup first time window resolution
gfxmode.x = System:GetProperty("screenwidth",gfxmode.x)
gfxmode.y = System:GetProperty("screenheight",gfxmode.y)
windowstyle = Window.Fullscreen
System:SetProperty("fullscreen","1")
--write graphics settings to savefile
savefile:WriteLine(gfxmode.x) --x resolution
savefile:WriteLine(gfxmode.y) --y resolution
savefile:WriteLine(1) --fullscreen
local quality=System:GetProperty("lightquality")
savefile:WriteLine(quality)
quality=System:GetProperty("terrainquality")
savefile:WriteLine(quality)
quality=System:GetProperty("texturedetail")
savefile:WriteLine(quality)
quality=System:GetProperty("anisotropicfilter")
savefile:WriteLine(quality)
quality=System:GetProperty("verticalsync")
savefile:WriteLine(quality)
--write audio settings to savefile
System:SetProperty("currentsong","0")
System:SetProperty("ambientvolume","0")
System:SetProperty("musicvolume","0")
System:SetProperty("effectvolume","0")
savefile:WriteLine(0) --currentsong
savefile:WriteLine(0) --ambientvolume
savefile:WriteLine(0) --musicvolume
savefile:WriteLine(0) --effectvolume
--write unlocked maps to savefile last
maplocked={}
maplocked[1]=false
maplocked[2]=true
savefile:WriteLine(0)
savefile:WriteLine(1)
else --apply savefile
maplocked={}
for a=1,14 do
savefile:Seek((a-1))
System:Print(savefile:ReadLine())
System:Print(savefile:GetPos())
savefile:Seek((a-1))
if a>12 then
if savefile:ReadLine()=="1" then
maplocked[a-12]=true
else
maplocked[a-12]=false
end
elseif a==12 then
System:SetProperty("effectvolume",savefile:ReadLine())
elseif a==11 then
System:SetProperty("musicvolume",savefile:ReadLine())
elseif a==10 then
System:SetProperty("ambientvolume",savefile:ReadLine())
elseif a==9 then
System:SetProperty("currentsong",savefile:ReadLine())
elseif a==8 then
System:SetProperty("verticalsync",savefile:ReadLine())
elseif a==7 then
System:SetProperty("anisotropicfilter",savefile:ReadLine())
elseif a==6 then
System:SetProperty("texturedetail",savefile:ReadLine())
elseif a==5 then
System:SetProperty("terrainquality",savefile:ReadLine())
elseif a==4 then
System:SetProperty("lightquality",savefile:ReadLine())
elseif a==3 then
System:SetProperty("fullscreen",savefile:ReadLine())
elseif a==2 then
System:SetProperty("screenheight",savefile:ReadLine())
elseif a==1 then
System:SetProperty("screenwidth",savefile:ReadLine())
end
end
end
So my problem is that ReadLine() isn't returning the next line I expect it too. I'm not sure what values to input into Seek() to move to the next line in my text file. Any help would be very much appreciated!
I'll also attach the text file this script creates on my computer to this post to show what it looks like.
snowboardingsavefile.txt