1
\$\begingroup\$

This is a snapshot of the dialogues written in a .json file stored in the Resource folder, which I use to display dialogues in the game:

{
"dialogues":[
    {
        "characterType": 0,
        "name": "Hero",
        "atlasImageName": "Hero_Default",
        "dialogueText": "Time to address the call to adventure"
    }

An advantage I can think of using .json is that you can directly edit it in a text file.

Beyond this, is there a reason to prefer JSON over hard coding in C# classes or structs? I feel like managing hundreds of JSON files is equally difficult as managing hundreds of .cs files that are used for storing dialogues, but with .cs files I can rely enums (for character types) and string-constants (for hero names) to minimize typos.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can serialize/deserialize c# types to/from json. I don't know the best way to allow string formatting in json but there should be smart people on the web that has done that... \$\endgroup\$
    – Emil
    Commented Oct 12, 2020 at 6:54

1 Answer 1

3
\$\begingroup\$

The main advantage is not mixing data with process. Separating them out means it becomes far easier to not cross wires down the road, and work on one without accidentally touching the other.

Having dialogue in json, xml or custom data formats also tends to make it shorter and more human readable.

Finally, it prevents having to recompile your scripts every time you fix a typo.

\$\endgroup\$
2
  • 5
    \$\begingroup\$ A few more advantages to chime in: It lets you expand or update your text with a new data pack download, without installing a new executable. Your game could switch between hundreds of different stories without bloating the size of the core program. The separation can make it easier to translate too, since you don't need to find C# programmers to do the translation. And it can be easier to feed through other pipeline tools like data validation, indexers, generative tools, etc, which don't need to compile C# to extract or manipulate your data. \$\endgroup\$
    – DMGregory
    Commented Oct 12, 2020 at 9:14
  • \$\begingroup\$ @DMGregory make that an answer? \$\endgroup\$ Commented Oct 12, 2020 at 17:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .