Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Possible Duplicate:
How to choose how to store data?

The game I'm designing will be mainly written in a high level scripting language (leaning towards either Lua or Squirrel) with a C++ core. In addition to scripts I'm also going to need different data files. Many data files will be for static information such as graphical assets and monster types. I'd also want to create and update data files at runtime for user information like option settings and game saves.

Can I get away with using plain script files (i.e. .lua or .nut files) for my data files, or is it better to use dedicated markup formats like XML or YAML?

If I use script files, loaded separately from my true scripts, then I wouldn't need an extra library to read those files. Scripting languages like Lua also have table syntax that lend themselves towards data definition. On the other hand I'd have to write my own schema check code. These languages also don't seem to support serialization "out of the box" like the markup format libraries do.

share|improve this question

marked as duplicate by Nicol Bolas, Byte56, Sean Middleditch, bummzack, Josh Petrie Dec 7 '12 at 16:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Which one you use is entirely up to you. Any of these will serve your needs. So what matters is how important the various features are for your needs. You know your needs better than we do. How much do you value runtime validation of data? If you wrote these files, are you concerned that they may become invalid? How much does serialization matter to your needs? Etc. You can answer these questions; we cannot. –  Nicol Bolas Dec 5 '12 at 1:00
We can't really tell you what to choose, but the duplicate linked can tell you how to choose. Personally, I'd go with XML if you're wanting end users to be able to read/edit the data, otherwise just go with serialized data. But it's up to you. –  Byte56 Dec 5 '12 at 1:00
The How to choose how to store data? question was interesting, though I'm more curious about the specific tradeoffs between defining and loading data from an XML file vs. a Lua file. –  Aaron Dec 5 '12 at 1:06
@Aaron: You know what the tradeoffs are; you mentioned them in your question. So what exactly are you looking for, validation that there aren't any other factors? –  Nicol Bolas Dec 5 '12 at 1:08
Not really a duplicate, the linked question is about data files vs. databases, this one is about data files vs. scripts. –  Laurent Couvidou Dec 5 '12 at 9:08

2 Answers 2

up vote 3 down vote accepted

I recommend using a markup format rather than putting all of your data in script files. The main reason being that editing and generating JSON or XML will be easier than generating comparable Lua or Squirrel code due to the availability of JSON and XML libraries. Another reason is it allows you more flexibility by keeping the data in its own format, and the scripts in their own format:

  • If you decide to change scripting languages your data will still be usable.
  • If you decide to not use scripting at all your data will still be usable.

In fact, you could take things to the other extreme and even store Lua or Squirrel code chunks in your data files -- but this is probably something you would want to avoid to keep your data and scripts clean.

A note about JSON and Squirrel: Squirrel 3.0 supports JSON-like declaration of objects, so you could actually use raw JSON strings and the Squirrel VM can parse them into tables. I see this as an advantage of using both technologies together.

share|improve this answer
Humans know squirrels like ninjas know flash powder. –  Arcane Engineer Dec 6 '12 at 21:23

Can I get away with using plain script files (i.e. .lua or .nut files) for my data files...

Sure, that's a valid option.

I've worked on a game where a good chunk of the data files were written in Lua, nobody got hurt too bad, and it had some benefits:

  • Lua table syntax is quite human readable, even if it has some quirks.
  • One "parser" for everything (actually a bit more than a parser, the fantastic LuaBind). This can actually be a good thing: smaller code base, less things to maintain.
  • You get "programmable data": it's easy to add a little routine in a data file e.g. to generate lists of things or parameterize some parts. I'm quite sure this sounds horrible to some ears, but it can actually be really useful for rapid prototyping. Just use it wisely, and refactor away the parts that get too dirty.

...or is it better to use dedicated markup formats like XML or YAML?

That is yours to tell, there is no such thing as the best option.

Of course there are some downsides to the data-as-scripts approach, Zack The Human mentioned some of them in his answer. I'd add that tool support is something very important to consider before going this way. There are good tools for editing regular data formats (XML, JSON), but you'll probably have to roll your owns if you plan to use a scripting language.

As usual the final choice is yours, just go the way that seems to suit your project the best.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.