Jump to content

Need Help with Stream:Seek()


Haydenmango
 Share

Recommended Posts

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

Link to comment
Share on other sites

System::Set/GetProperty() automatically does this by reading your <GameName>.cfg file located in AppData. If your game is using the stock lua app, you should be set.

But if you want to make your own system, then I recommend you create a module class that for each line it reads it will extract the key and value from the string based on the location from the equal sign.

  • Thanks 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

I remember I worked on this, trying to make a savefile too, but it is long ago, well I can remember that Seek could be used with an Intervall of 4. I could not understand why but it works, so something like,

Seek(n)

Seek(n+4) ----- and not n+1

This should be re verified, maybe it is useful

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...