# Unity (C#): How can I create dialogue to be used in my game? (also critique my system?) [closed]

I've created my own system for handling dialogue. There's a class for each 'node' or part of dialogue. It contains the following variables: identifier (identifiers are unique for each NPC, but not globally, ie "1", "2"), a text variable, a list of strings (which are the option button values), another list of strings (which contains option identifiers), and a string which is used for passing custom functions through. A collection of these Dialogue classes are made, and then stored in a dictionary, with the key of each being the identifier.

public string identifier;
public string text;
public List<string> options;
public List<string> optionIdentifiers;
public string onCloseFunction;

public Dialogue(string identifier, string text, List<string> options, List<string> optionIdentifiers, string onCloseFunction = "") {
this.identifier = identifier;
this.text = text;
this.options = options;
this.optionIdentifiers = optionIdentifiers;
this.onCloseFunction = onCloseFunction;
}


At the start, the dialogue with identifier 1 will be chosen, and the text displayed, with each of the buttons.

If the first option is chosen, that is index 0 in the options list. The index selected is used to get the correct identifier from the identifier list, which will return "2_1". This is then used to find the next dialogue.

The system fortunately works, however I'm wondering if I've overcomplicated this, and if there's a simpler way to do this.

Building further on this, it isn't easy to sort out the conversations to appear in. I have made the class 'Dialogue' serializable, so the properties are displayed in the unity window. I've made a public array of dialogue, which then is turned into a dictionary with the corresponding key identifiers.

public Dialogue[] dialogueList;
public DialogueLibrary dialogueLibrary;

void Awake() {
Dictionary<string, Dialogue> dict = new Dictionary<string, Dialogue> ();
for(int i = 0; i < dialogueList.Length; i++)                // Add all dialogue from inspector into dictionary
dialogueLibrary = new DialogueLibrary (dict);
}


This allows me to add dialogue as such:

The biggest problem I have with this, is the fact that it's just... not very nice to deal with. For example, if there were 30 pieces of dialogue, and I wanted to add another between 2 and 3, I would have to either increase every identifier afterwards, or use something like 2a for an identifier. Furthermore, it would be a lot better if I could read the dialogue list from an XML file.

What I'm stuck with is how I can create this XML file. I need some software that can simply create the conversations and export them in XML. Honestly I'm not sure how to go about this. Is there any software which exists already which could do something like this, or should I create my own in Visual Studio? I'm not sure how I'd go about creating something like this in visual studio. Ideally the software would be similar to mind maps, where the node of text is the dialogue text, and the connecting arrows have text on, and are equivalent to the options. Identifiers should ideally handle themselves.

Can anyone give me any pointers in what direction I should take, and if the direction is creating my own program, could anyone suggest any resources which would help me?

I understand this is a long message and I'm asking a lot, but any help, comments or even constructive criticism on my system would be greatly appreciated. Thanks in advance.

## closed as unclear what you're asking by DMGregory♦, Seth Battin, Anko, congusbongus, Tom 'Blue' PiddockJul 13 '15 at 12:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• The folks at Inkle (makers of narrative games like 80 Days) gave a great talk about their process at GDC this year. You can watch the video free online. They strongly suggest using a text file for writing the script, and they show some examples of formats they used. They found this let them iterate much faster than node/inspector-based approaches, and their custom markup is much leaner/friendlier on the eyes than XML. – DMGregory Jul 1 '15 at 14:35
• That was interesting to watch, thanks. How would I go about making a system like this? – Jacob Morris Jul 1 '15 at 16:20
• That's well into the territory of "too broad" ;) Try planning out what you want, figure out which parts you already know how to do or can find online tutorials/documentation about, and if there's still an aspect you're not sure about, post a specific question detailing exactly which piece of the puzzle you need help with, and what you've tried so far. – DMGregory Jul 1 '15 at 16:23