Storing Data

Hey, im wondering wat would be the recommanded way to store data for a game (say the player info, stats, etc.) in such a way that it would easiely be accessible and sortable

i really liked how SQL worked, it allowed u to count the number of entries, sort them only if a certain attribute is equal to set value

for example
GET .... WHERE GameMode == 1 AND ((CurrentDate - GameDate) <= (60 * 60 * 24 * 7))

to get all the data stored in fields where game mode is 1 and the date was less than a week ago

i realize it is not requested that way to the SQL server, but i havent done any SQL and PHP in a long time, so i dont really remember. it is just to explain that i feel like using arrays & such in C++ really wouldnt do as great of a job as that did, i figured there might be a better way to store data without taking huge memory
Last edited on
If you don't want to store it in RAM (variables, program's memory), then you can store it on the Hard Disk (text files, databases.) However then you have to open a file stream and read/write to disk every time you need to update something. You can always find a happy medium.
If you're talking about non-persistent game variables, just use variables (as part of appropriate class instances).
If you want to store data between sessions (e.g. in a savegame), serialize your data into files.
If you have a lot of data to store (such as when writing a server for an online game), use a database (SQLite is one of several possibilities).

Edit: much too slow.
Last edited on
ok, so storing in files would be the best way, im guessing u would have to set up say something like this
1 line = 1 entry
and the separate your fields with some weird characters that cant be used in the data ull store (say °°) to separate your fields?

also, since this would store data on a hard drive, it would most likely be on a server, so im guessin ill have some networking to do early on? :/
ok, so storing in files would be the best way, im guessing u would have to set up say something like this
1 line = 1 entry
and the separate your fields with some weird characters that cant be used in the data ull store (say °°) to separate your fields?

That's one way, a better one is to store your values in binary form. XML is also an option that has its advantages.

also, since this would store data on a hard drive, it would most likely be on a server,

Elaborate. What does the one have to do with the other?
Well you store it to your server's hard drive, which is local as far as the server program is concerned. However for the server program to talk to the game you will need to network.

And yes, any delimiter should work. Also remember you can use an obscure string of characters too like ";;;" could be the delimiter as long as no data could start or end with a ';' character (and of course didn't contain any ";;;" substrings.)
Last edited on
Topic archived. No new replies allowed.