Save Game / Load Game Help

mattkw80

Well-known member
Joined
Jan 3, 2008
Messages
49
Location
Ontario, Canada
Programming Experience
Beginner
I am writing a Pokemon style RPG game in Visual Basic.

There are hundreds of variables, that represent the character's stats, and as well, things that have been "unlocked" during game play, world events, etc.

Does anyone know a really simple way of "freezing" all the variables in place so that I could then read that state, and load it again. (Basically, a SAVE game and Load Game method) without having to type out every single variable there is.

Right now what I do have working, put is a pain to maintain is a system that dump all the variable values to a textfile, and then my load method reads them all back.

ie:
Code:
'SAVE GAME

        objWriter.WriteLine(cash)
        objWriter.WriteLine(health)
        objWriter.WriteLine(magic)
        objWriter.WriteLine(ammo)
        objWriter.WriteLine(level2unlocked)

'LOAD GAME

            cash = objReader.ReadLine()
            health = objReader.ReadLine()
            magic = objReader.ReadLine()
            ammo = objReader.ReadLine()
            level2unlocked = objReader.ReadLine()
This does work - but it sucks to have to update everytime I add new variables to the game, and as well, new versions of the game cannot properly load old version of save files.

Anybody know a clever way of handling this problem?
 
Last edited by a moderator:

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
I would highly recommend using XML for this, XML saves things as plain text so manual editing could be done in windows notepad, should you need to, but XML allows you to specify fields and XML does allow the schema to be saved to the same file.

Either way, when you add more variables to the game, you're going to have to add them to the load/save routines, but at least with XML it's a little easier to do once the structure's set up
 
Top Bottom