Different data on different files?

Hi,

I am developing a game that has many things to be saved. Should I save every thing
onto one file(I dont know how to make it read specific lines) or make different files for everything(Easy, but concerned about junking up mem)?

Thank you
I'd start with a single file and only use separate files if you have several different types of data, such as text and images.
I'd start with a single file and only use separate files if you have several different types of data, such as text and images.

Could you give me an example of reading diff. lines of a file(say level is on one line, and weapon is on another)?
Well, its up to to you. For example you could make sure the data is always in a specific sequence, so that line 1 contains the level, line 2 contains the weapon and so on.

A more flexible arrangement is to use a keyword followed by its value
For example the file might look like this:
level 1
weapon peashooter

Or use a particular delimiter, such as an equal sign:
level=2
weapon=rifle


As you can see, there are many choices of how to store the data. Depending on that decision, the means of retrieving the value would vary.

There are two problems here. The first is identifying what type of information is on a particular line. The second is that some data could be either a string or a number (I assume - but you haven't actually said so).

In simple terms, read the first value on the line as a string. Depending on its contents, decide what to do next.

1
2
3
4
5
6
7
8
9
string keyword;
int level = 0;              // default value
string weapon = "feather";  // default value

infile >> keyword;
if (keyword == "level")
    infile >> level;
else if (keyword == "weapon")
    infile >> weapon;

I was thinking yesterday, would using MySQL be easier?
Depends. It could be using a sledgehammer to crack a walnut. It also means the program isn't stand-alone, as it requires the database program to be running too.
You'd still have to design the required table(s) and generate (by hand coding or otherwise) the relevant SQL.

In the right context, MySQL is a good solution. But perhaps for simple cases it's easier to just use an ordinary file.
Thank you Chervil
Topic archived. No new replies allowed.