Saving a game

BlitzPlus Forums/BlitzPlus Programming/Saving a game

Eviltoes(Posted 2007) [#1]
How would I go about saving games in blitzplus, because I am working on a simple RPG game, and an RPG(or pretty much any other game) isn't much fun if you have to start over every time you play it.

I need to know a way to save:

Which characters are in your party.
Every character's stats.
Every character's equipment.
Location.

AND

Progress through the storyline(or sidequests).



Thanks for any help!


Petron(Posted 2007) [#2]
Readfile
Readline
Writefile
Writeline
Closefile


Lelldorianx(Posted 2007) [#3]
Is there anyway I could get more of a response than this, Petron?

I too am having this problem. Are you saying I *could use anyone of those* or that I need to use all of those?

Thanks, any short example will do if someone could help with one :P

Would it be something along the lines of

If ;they type save$ then
writefile "name.???"


CS_TBL(Posted 2007) [#4]
There's an excellent example in the manual, did you try that first?


Lelldorianx(Posted 2007) [#5]
I have the Game Programming For Teens Second Edition that I bought 2 years back (however I just came back to it and must relearn). I have not seen one in here, is it in *this* manual? Or is there a different one from the site to DL?

Edit: I see these are for highscores, I can use it for the actual game information (i.e how far you have progressed, items, etc.) as well right? Just make a constant command that is Save or something, that they can type, and then initiate a save sequence to remember exactly where they are.


deps(Posted 2007) [#6]
Saving a game:

- Open file for writing
- Write some kind of header. A short one word text string like "MYSAVEFORMAT"
- Save how many characters you have in your party.
- Then for each character:
* Save stats
* Save equipment
* Save location
- Save what quests that is finished
- Save what quests that is currently active
- Close file


When loading a savegame:

- Open file for reading
- Read in the headerfile and check if it is valid.
- Assuming the header was correct:
- Read number of party members
- For each party member:
* Read stats
* Read equipment
* Read location
- Read list of finished quests
- Read list of active quests
- Close file

With the info you provided us with, there really is no other answer. Check the manual on how to open,read,write and close files, then use that to store everything that is important. It's as "simple" as that.

EDIT:
The relevant parts of the manual is these:
http://blitzmax.com/bpdocs/command_list_2d_cat.php?show=File
http://blitzmax.com/bpdocs/command_list_2d_cat.php?show=File/Stream

You want to use WriteFile( "mysavefile.dat" ) together with WriteInt, WriteString and/or any other Write* command in there for creating the savegames.

Then use ReadFile( "mysavefile.dat" ) together with the Read* functions to load it back in again. Make sure to read in the same order you write the data.


CS_TBL(Posted 2007) [#7]
When ppl refer to 'the manual' they refer to the built-in manual of Blitz.. the 'F1'-key so to say..


deps(Posted 2007) [#8]
Do the built-in manual differ much from the online one? I use the Online Blitz3D manual a lot when I'm using MiniB3D.


CS_TBL(Posted 2007) [#9]
The built-in manual of B+ is ok. All the native stuff like files is explained well.