Search Unity

When making a heavily story-based game/visual novel, where do you keep the text? (array of strings)

Discussion in 'Scripting' started by WizardXZD, Jul 4, 2019.

  1. WizardXZD

    WizardXZD

    Joined:
    Jul 14, 2018
    Posts:
    4
    Making a game with a decent amount of dialogue.

    I've seen a few tutorials on making dialogue systems.

    However, they ALWAYS use arrays of strings to hold all the dialogue.This seems super inefficient for games with more text than just a few lines?

    Wouldn't it be easier to just write the dialogue in a .txt file and read that? I've never done this before, so I might be underestimating how much work it would be, but I would imagine it's a lot easier to edit text that way.

    Has anyone had experience with working with a lot of dialogue, and what did you do?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,171
    L. Tolstoj War and Peace in unicode occupies about 3 megabytes. If your texts are really much larger than that...
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,092
    You can hard-code text into the game code, which requires the least actual code and results in the most-brittle and hardest-to-update approach.

    You can put it into txt files or into ScriptableObjects or into JSON files or whatever, but each of those approaches will take you some time to write the tooling.

    If you want to get a jump on things, look at more already-written text dialog system. If you're done with that part of things, just start coding and see how it shakes out, and over time you can look for ways to abstract and package things such as dialog trees, or individual lines, or whatever. Much of how you solve it is going to depend on the complexity you're trying to achieve.
     
    Laperen and lordofduct like this.
  4. baxcet20

    baxcet20

    Joined:
    Jul 1, 2019
    Posts:
    28
    It's best to put in a dictionary in your own program so that you can instantly call it. Reading it off harddrive will take additional time and searching, when it's part of your RAM, it will be way quicker. I would personally make a static class and just dump dialogue in a massive dictionary to be honest.
     
  5. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    253
    Unless you have done something very wrong, loading text dialogue for your game from a file should take milliseconds.
     
    Kurt-Dekker likes this.
  6. doctorpangloss

    doctorpangloss

    Joined:
    Feb 20, 2013
    Posts:
    216
    Using Ink for dialogue is probably the best approach for Unity nowadays.

    Additionally, your writers will thank you for offering a dialogue system similar to actual writing.
     
  7. bart_the_13th

    bart_the_13th

    Joined:
    Jan 16, 2012
    Posts:
    440
    I usually use json formatted string in a text file. The format should be readable enough for your story writer. Something like
    Code (csharp):
    1.  
    2. [
    3.    {
    4.        "name":"NPC 1",
    5.        "expression" : "normal",
    6.        "text" : "bla bla bla"
    7.    },
    8.    {
    9.        "name":"NPC 2",
    10.        "expression" : "angry",
    11.        "text" : "bla bla bla too"
    12.    },
    13.    {
    14.        "name":"NPC 1",
    15.        "expression" : "normal",
    16.        "text" : "bla bla bla again"  
    17.    }
    18. ]
    19.  
     
  8. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    813
    Having an editor tool to handle the creation of your dialogue trees will do wonders for your development time, especially if it's a node based system for your editor. The nodes will probably be scriptable objects in data form, but is essentially a string array in a scriptablt object. At that point your dialogue can simply be stored in the scriptable objects.

    The only reason I can see to store your dialogue in a text file is if you want to handle localization. That requires another system altogether, but needs to work together with whatever you use to display text on the screen.

    If you have your dialogue in text files, it is easy to send it to a translator who doesn't need to know what your game is like or context of the dialogue, but still be able to do their job and give you a translated version of your text. You should then simply be able to plug the translated file into your game, and have the game read off the translated text without issue.

    The reason why you need an editor to handle dialogue trees instead of have it all in a text file matters when you have decision points in your dialogue. There isn't an easy way to handle that in a text file, nor will it be neatly represented if you did. Confusion is the enemy of development time, so avoid it wherever you can.
     
    Last edited: Jul 5, 2019
  9. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    342
    Depending the amount of dialogue, I'd probably just use JSON or make a domain specific language for it. Hard-coding text is an extremely bad idea, and IMO text should be kept entirely separate from code.

    Is your plan to use branching dialogue, or just a completely linear conversation? Do you want dynamic text(like inserting the player name)? Do you want choices to depend on skill checks or something like that?