Hard coding or data files?

My game is developing a good deal of dialogue text, and I have been hard coding that into the game. But is it better to use data files and load when needed?

Especially for dealing with altering dialogue scripts etc. Say if you want to alter a character’s lines. Basically talking to npc’s is a major part of this game and we want them to have rich varied dialogues. But it seems that hard coding it doesn’t seem the best way to do it.

If it were a online game I’d use a database but it’s not.

Any thoughts?

JB Skaggs

I’d choose data files. Easy to edit, and you don’t need to know programming to edit it.
Also, one big advantage is that if you choose later to make your game multilingual, it will just be a matter of translating those data files and swapping them.

No need for a database unless the lines of dialogue must be the result of very complex queries. But data files are certainly the way to go. That’s also the way that localization is handled: you write a dialogue file(s) in English and you structure the application so that it can load the same files in other languages too.

Even if localization is not your aim though, the general wisdom of software is to hardcode the least you can and use as much as possible a “soft” architecture, one with data files storing all sorts of resources that are loaded by the “hard”(-coded) architecture, as needed. This is also the basis for “modding”. Dialogue files, 3d models, animations, textures: they should all be outside the code so that they can be easily replaced and modified.

Ultimately it is also for your own benefit: if the data is hardcoded, every time you change the data there’s a non-zero chance you’ll introduce bugs in the application.

Hope it helps!

Thanks a bunch that really does help.

JB

I’m a biz programmer by trade, but definititely data files are the way to go, espeically for an rpg-type game.

For my game, I’ve got simple “character” text files that my functions read to determine what character model and texture to load as well as special anims to load and various game attributes to assign (speed, AI, etc). This makes it easy for me to add new unique units to my game in the future.

I also use them for maps (simple lists of objects,lights,characters to load and where to load them at the start of a level) and will probably add text speech data files soon.

If a change should be logged nonmanual, I’d make tables in a database for this. Speaking of while developing.

The rule of thumb: put stuff in data files instead of hard-coded as much as you can. The main exceptions to this rule are if things are taking too long to load; hard-coded is usually faster, but frankly the situation is rare when your long load times aren’t bottle-necked by things that can’t be hard-coded like textures and sounds.