Save System Help

Blitz3D Forums/Blitz3D Beginners Area/Save System Help

mintybreath(Posted 2007) [#1]
I am making a 2D overhead freeroamer game, and need a little help with the save system. Well, i figured, how i would make one, is have a button, and when ever the arrow overlaps it, and mousehit(1), it would write the information to a file called Save File.dat , or something along the lines of that. So i tried it out. I made it so it writes the amount of ammo the player has to the file.
The problem is when i read it. Maybe i dont understand file writing enough, i dont know. But what i dont understand is how do you know what you are reading. What if i say,

Ammo= ReadInt(FileIn)


And instead it reads out the amount of money. I was reading the example for how to read. Maybe wat i am doing wrong is i am not putting it as part of the type?

Im not sure. I someone could tell me how to read correctly, and maybe even some about writing correctly that would really help.
Thanks everyone!

From,

Kevin


Stevie G(Posted 2007) [#2]
This is how I would do it ...

You need to bear in mind that the file is read in the order it was written.

type Player
   field ammo
   field money
end type
global ME.player = new Player
ME\ammo = 10
ME\money = 5


Function SAVEgame( filename$ )

   file = writefile( filename )
   writeint( file, ME\ammo )
   writeint( file, ME\money )
   closefile file

End function

Function LOADgame( filename$ )

   file = openfile( filename )
   ME\ammo = readint( file )
   ME\money = readint( file )
   closefile file

End function



Gabriel(Posted 2007) [#3]
Or you could use the XML format for your saves, then it doesn't matter what order you read and write your data, because data is indexed by a name ( String ) so you can just tell it you want "ammo" and it will get that value. The main advantage being that existing save games don't become invalid every time you change the format or start saving out new information.


mintybreath(Posted 2007) [#4]
Oh ok, i think i get it now. Thanks alot.

As always if i need more help, ill post back here. :)