user238033
user238033

Reputation:

What's a good file format to use for storing player saved files?

I'm making a game in Java, and I need a good file format to store the player's saved data.

Any suggestions?

Feel free to give examples in code if you want.

EDIT: This is a server-client game, so the saved data will be on the server's machine. Also, I don't want to use Serialization.

Upvotes: 2

Views: 2230

Answers (5)

saolof
saolof

Reputation: 1641

Just use SQLite for local saves or a server-side database for server side saves. It would have been a good maybe-slightly-overkill answer when the question was asked, and unlike XML it still is a good answer now. If your save files ever grow above a kilobyte and stop being trivially user-editable, use sqlite.

Upvotes: 0

Ron Savage
Ron Savage

Reputation: 11079

If as you say, the information will be saved on the server it should definitely be in a database. The typical game protocol is store the user information in a database - pull it into memory when they login, with lazy updates to the db for changes to the object in memory (keeps game performance high) as they play the game and update their "in memory" user game state object.

Don't limit the scalability of your game by starting with file based storage just because it might be slightly easier.

Upvotes: 2

Brendan Long
Brendan Long

Reputation: 54252

All of the answers so far seem to be about XML, which isn't a bad format, but there are other options you might find useful, which should make your startup times faster:

Json: Common and has been around longer than my next two suggestions.

Thrift: What Facebook uses. Should be faster than Json, supported by less languages.

Protocol Buffers: Used by Google. Probably the fastest, and also easy to extend.

Or just make your classes support Serializable.

Upvotes: 3

Vivek Bernard
Vivek Bernard

Reputation: 2073

Since its your game, you could define a file format yourself. For saving game's state directly serializing and storing will do. As for the players saved data (which could be his level progress, game score etc) you could use XML.

<?xml version="1.0"?>
<Game>
<player  id="01d">
     <name>
             John
      </name>
      <skill>
        Rookie
      </skill>
      <score>
       122
      </score>      
</player>
</Game>

Ofcourse you could encrypt it to make it hack-proof

Upvotes: 1

drfrogsplat
drfrogsplat

Reputation: 2657

XML

let's you save any data structure you may have in a standard format and you won't need to write your own parser/writer for it

if you need the files to be "secured" from gamers changing their scores/progress/... (not sure where the files are stored? or whether this matters?) you could pass the XML through an encryption algorithm or encrypt the data elements before putting them into the XML

Upvotes: 3

Related Questions