How to add new dialogue

This tutorial helps you to understand how to create dialogues files

Files & folders needed:

assets/dialogues/

assets/creatures/characters.json

PITO Dialogue Editor - tool for dialogue creation/editing (.NET 6.0)

All game dialogues placed at assets/dialogues/ folder. Name of the dialogue file is it's unique ID.

The JSON structure of dialogue file:

{
  "start_dialogue": "DIALOGUE ID", // phrase object that will be ran firs
  "dialogues": { // array of phrase objects 
	"DIALOGUE ID": { // ID of phrase, used in "start_dialogue" and in "go_to"
	  "text": "TEXT IN NPC WINDOW", // NPC talking text
	  "answers": [ // array of player's answers objects, amount of objects equal phrases amount
		{
		  "text": "PLAYER ANSWER", // answer text, please, use lang key
		  "go_to": "NEXT DIALOGUE ID, OR SPECIAL KEYS (close_dialog - close dialogue window, close_game - quit from game)",
		  "condition_has": "event.key.id" // answer will be shown if player has this event key (optional)
		  "condition_has_items": ["af_bengal"], // array of item_id that must contains player to show this replic (optional)
		  "condition_money": 600, // if player has this amount of money, replic will be available (optional)
		  "actions": { //actions (optional)
			"add_money": 0,
			"del_money": 0,
			"add_e_key": ["event.key.id"], // you can create any id, just remember it for usage
			"del_e_key": ["event.key.id"], // delete keys
			"add_quest": ["quest_id"], // add quests
			"add_item": ["item_id"], // add items
			"del_item": ["item_id"] // delete items
		  }
		}
	  ]
	},
	... // can be many as possible
}
Dialogue logic diagram

Editing and creation will be made with Dialogue Editor.

Dialogue Editor workspace
1. Dialogue file drop down selector
2. Start dialogue phrase ID dropdown selector
3. Dialogues phrases nodes list
4. Add new dialogue phrase node
5. Dialogue phrase node
6. NPC Text area of edited phrase node
7. Player answers nodes list
8. Add new answer node
9. Player answer node
10. Create new dialogue file
11. Save current dialogue file to different file
12. Save current dialogue file
13. Node graph preview of the dialogue file as visual structure with blocks and connections
14. JSON structure of the current dialogue file

Download dialogue editor and unpack files from it into root game folder near assets folder.

Here is you can see workspace for working with game dialogues files, in left top corner you have dropdown menu that contains all game dialogues. By selecting one of the element, you can start work with it.

Now you can see at the right side at the top corner Start Dialogue ID drop down menu, it contains all dialogues IDs that can be showed at the start of conversation with NPC. You can select what ID will be shown first by selecting element from the drop down,

or left click at the title of the Dialogue Node in the Dialogues Nodes list.

Dialogue Node title
Message when clicked at Dialogue Node title

Every dialogue node has ID, NPC Text language key preview and amount of player answers. Dialogues can be created by Add Node button or deleted from the Dialogues Nodes list by pressing red Delete button.

To edit dialogue phrase, click at Edit button and it will set your workspace to dialogue edit mode, and at the left side you will see a list of Player Answers, that has Answer number, answer language key text preview, Next dialogue drop down menu, conditions and actions amount.

You also can move answer block up or down it will change in-game order of the player answers. And also, you'll be able to change current dialogue NPC Text at the top left side of the workspace. Any changing to the text will save it to the temporary data container that hold all dialogue data before you will save it to the file.

So don’t forget to save file by clicking save or save as buttons at the bottom of the workspace.

Answers can be Deleted or Added by clicking Add New button at the top right corner of Player Answers list.

Keep in mind that you can create answers only in Dialogue Edit Mode at dialogue node.

You can change answers conditions and actions by clicking big Edit... button in answer node. You will see a window called Condition Editor.

Here you can add some conditions for showing player answer and some actions that will be executed when player will click at it.

Current active conditions or actions will be shown as numbers, so you can understand does the answer contains some conditions or not. To make condition - simply fill one of the condition fields and condition will be active, same for the actions and press Apply.

If you want to delete conditions and actions, make text fields empty and set number fields with zero and press Apply.

You can preview your dialogue structure as JSON and as Node Graph.

The JSON structure is used by the game, so you can check if everything alright and correct.

JSON Structure

The Node Graph structure can help understand connection between dialogues and answers.

After creating and saving dialogue file to assets/dialogues/ folder, open assets/creatures/characters.json file to add new dialogue to the NPC profile.

How to create NPC profiles, you can learn a little in this tutorial:

How to edit traders

The NPC profile contains "dialogues" property list [], it can contain structure like this:

characters.json -> profile
"dialogues": [
    {
        "dont_has_event_key": "harya.gived.quest.bandits",
        "dialogue": "harya_dialogue"
    },
    {
        "has_event_key": "harya.gived.quest.bandits",
        "dont_has_event_key": "harya.bandits.completed",
        "dialogue": "harya_dialogue",
        "start_phrase_id": "harya_start_quest_accepted"
    },
    {
        "has_event_key": "harya.bandits.completed",
        "dont_has_event_key": "harya.second.dialogue",
        "dialogue": "harya_completed_bandits"
    },
    {
        "has_event_key": "harya.talk.done",
        "dialogue": "no_dialogue"
    }
]
All dialogues will be show from top to bottom if conditions are done.
So we need to separate each dialogue by conditions (event keys).

has_event_key = (optional) check if player has event key
dont_has_event_key = (optional) check if player has not event key
dialogue = dialogue file name from assets/dialogues/
start_phrase_id = (optional) overwrite start dialogue id in file

So if we want to always show our new dialogue forever, use this structure:

"dialogues": [
    {
        "dialogue": "my_dialogue_file"
    }
]

If we want show dialogue only by condition (if no condition done, we can't talk)

"dialogues": [
    {
        "has_event_key": "my.event.key",
        "dialogue": "my_dialogue_file"
    }
]

If we want use same dialogue, but after receiveing event keys, we can use this:

"dialogues": [
    {
        "dont_has_event_key": "my.event.key.1",
        "dialogue": "my_dialogue_file" // we add my.event.key.1 in dialogue
    },
    {
        "has_event_key": "my.event.key.1",
        "dont_has_event_key": "my.event.key.2",
        "dialogue": "my_dialogue_file", // add my.event.key.2 in dialogue
        "start_phrase_id": "my_dialogue_file_phrase_id"
    },
    {
        "has_event_key": "my.event.key.2", // no dialogue if have my.event.key.2
        "dialogue": "no_dialogue"
    }
]

Last updated