🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Pros and Cons of Dialogue Saved or in Code?

Started by
4 comments, last by HappyCoder 4 years, 4 months ago

I'm working on the design of a dialogue system, and I'm wondering about pros and cons of where and how to store the dialogue. The two key ways I'm looking at right now, are 1) store it in a JSON, XML or YAML file, including information on what events it should interact with, or 2) write the dialogue directly into code?

For either, I would certainly imagine writing tools to assist. for 1), a tool that automatically applies content to the UI or populates prefabs and for 2) a tool that helps find and identify either script sections by attribute, or to help select them in scenes and prefabs.

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

Advertisement

You should potentially prefer option 1 or have at least a really strong tool in the back if heading for option 2. The reason is simple, editing your content and of course localization.

Having anything in code not just causes your code to recompile every time you edit the dialog but also to make it really complicated if you one day decide to add another language or want your game to be localized to speech

Like Shaarigan said. Text must not be embedded in the code. It must be a separate, easily edited file. I am speaking as a producer, whose developer embedded text in the code on a past project. DON'T DO THAT.

-- Tom Sloper -- sloperama.com

Mostly in various programs I encountered ID strings like “new_game” with separate tables for all languages (and sometimes even as integers in the actual source via constants).

But another solution that I have encountered in a few applications is “gettext”. You write your program with the English string directly, then pass the strings through a “gettext” function (often shortened to `_` in programs I saw).

For the most part these didn't have a great deal of text, and certainly no “writer”. Strings were either what the programmer came up with at the time, or part of the overall UI design.

display(_("My name is %0."), my_name)

For most languages there is a program to scan the source and create/update text files for translations. Along with tools to check for missing or unused translations.

msgid "My name is %0."
msgstr "Je m'appelle %0."

This can also be done for datafiles, not just compiled/script sources.

An interesting feature is that changing the English string, automatically “breaks” the translation as you now have a new “msgid” that needs updating for each language, (e.g. if I rename a menu item, say from “Exit” to “Save and Exit” which in a string ID system I might leave as “menu_exit”), or minor ones like a change in capitalisation and punctuation ("save and exit.", “Save and Exit”), or style (“It will cost 1000s.”, “It will cost thousands.”).

Although any translations I did with ID strings, as far as I am aware all the translators did check to see which strings changed in the English table, not just entirely new keys (maybe they had a compare tool for this, not sure, was outsourced).

If you are the only one on the project would start with having the dialog code only. It makes is easier to add new features, keeps the tool simple, and you don't need to develop any custom tools for editing the text. Be sure you keep the dialog object in a easy to serialize format should you want to create a text parser for it later.

If you simply need a dialog system for a project I would take a look at ink
https://www.inklestudios.com/ink/
I've used it before and I think it does a great job building a feature rich dialog system that is easy for a non programmer. If you want to make a dialog system for the fun of it or because you need a specific feature I would at least look at ink for some ideas.

My current game project Platform RPG

This topic is closed to new replies.

Advertisement