#### Archived

This topic is now archived and is closed to further replies.

# Data files vs. text files

This topic is 5111 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I know only that which I know, but I do not know what I know.

##### Share on other sites
If the text files are plain numbers, characters, etc the don''t bother to use them. However...

...if the text files looks like:
character "GoodGuy"    icon icons/goodguy.pixmap    health 100    attribute main_character    [blahblah]

and
map Village    name "The Village"    width 18    height 30    for W use tiles/wood.pixmap    for . use tiles/grass.pixmap    for G use tiles/monster.pixmap    ....W.....W...GG..    ....WWWW WW...G...    [blahblah]

then do it (btw pixmaps are the X Windows bitmaps which are stored in plain text and they''re very easy to parse - also they''re supported by many drawing programs such as Paint Shop Pro and GIMP).

About speed, yes it will be slower. However a nice trick to overcome this is to cache the data in a binary file and each time you want to load the data, check the text file day. If it has changed (store somewhere the initial dates) then reparse it.

##### Share on other sites
Really, what you should do is work out a way to do things in binary and write an editor.

Text files are great, but they''re slow and can be edited by anyone. This not only compromises your game data, it can cause serious security issues if you''re not prepared to handle the situation where a user would REALLY mess up the files. Even then, you leave yourself open to holes you might not''ve thought of that clever users could exploit. Granted, you''re not safe with binary either, but at least users don''t have a clue what they''re editing then so taking advantage of security holes other than expecting the data to be fine all the time is less likely.

Furthermore, with more complex data you''ll probably find yourself being more productive if you have a utility to serve as an interface between yourself and the file. A map editor where you can draw using a tile palette, for instance, makes editing maps a real joke. I use VB to write up these kinds of utilities, since it''s fast and easy and performance isn''t an issue for a tool like that, personally.

Bottom line is that you''re better off with binary, but text is easier to edit. It''s up to you what you want to have.

##### Share on other sites
Exploiting the engine via text files sounds strange to me. However if it happens that means that features (bad or good) that the engine wasn''t supposed to support will be applied. Generally this sounds to me as a good idea for keeping up a community :-).

##### Share on other sites
If the game''s not networked, then there really aren''t any security issues (let them try to mess with the game as much as they want).

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

##### Share on other sites
I use both text and binary files. The editor that I''m currently writing saves it''s level data as text which also includes editor settings and information that won''t be present in the final game data. Saving the files as text allows me to tweak them by hand if needed. Text files are also more friendly to a lot of the revision control systems such as CVS although this probably isn''t an issue if you are working alone.
The editor and/or associated tools generate binary files containing the raw level data which is faster to load and also has less risk of generating errors (such as syntax errors etc).

##### Share on other sites

If you do decide to go with text files, I highly recommend that you consider XML files. The "extensible" part of XML is a very nice feature for the programmer, because if you decide to start including more parameters in your files, your old data files are not necessarily obsolete.

##### Share on other sites
Don''t be afraid to use text files. If you are loading a small amount of information ( or even a lot ) and you are only doing it once on startup or level load, the cost is pretty negligable. It makes it easier to debug and test, and people who are changing your product can easily see how it all works. If you are writing a game where you are loading a large amount of data, the look into using binary data. I find it often makes sense to use text first, and if it''s taking too long, move to binary after the fact. As a side note, I''ve been using TinyXML to write and parse xml save files and such for applications and tools and I find it very handy.

##### Share on other sites
Shameless plug for a library I made for a parser of configuration files (file format is my own but looks very similar to Lua or so I am told):

ConfigParser API

Regards,
Jeff

##### Share on other sites
IMHO, the programming / conversion overhead of using binary files is too great, particularly during development.

Use text files until there is a reason not to, and then stop.

If that reason never happens, continue to do so in the finished product.

There is no security advantage in using binary files over text, as each can be edited by the determined attacker. To make it more difficult to modify them, store some kind of checksum (perhaps in a separate file), and check it at runtime. Crackers can still modify your game whatever you do.

Mark

• 9
• 16
• 9
• 13
• 41