Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Dialogue

Luc-Frédéric Langis edited this page Jan 8, 2021 · 5 revisions

I try to create a simple but flexible dialogue system. Here how it working

  • NpcInteraction control player behavior and manage communication with the NPC
  • NPC will communicate with DialogueController
  • DialogueController will everything about the dialogue of the NPC
    • Load and search JSON file
    • Preload all portraits in memory
    • Communicate with the DialogueBox scene
  • DialogueBox is the dialogue UI, it will manage
    • Choices
    • Scrolling
    • Communicate with DialogueController about his own state

dialogues_uml

LE Dialogue Editor

I create a small tool to manage all my JSON dialogue files. You should use it to save time. You can download it right here and get the source code here (it also has its own wiki)

JSON file

JSON file should be placed inside res://assets/dialogues/ and should share the same name of the NPC's node name.

e.g. Jack will use Jack.json, JackLevel2 will use JackLevel2.json file. Of course, you can edit it, I through it was pretty useful for my workflow.

Understanding the JSON

I will just redirect you to LE Dialogue Editor's wiki

Managing parameters and type

If you are not used to json we are limited to the number of types. Type like Vector and Node doesn't exist in JSON. The way I overcome this issue is by

  • Signal without parameter are set with a null value
  • Signal with parameter are set as Dictionary in the shape of type => value
"signals": {
    "npc_script_event_started": null,
    "notification_started": {
    	"String": "dialogue generate event"
	},
	"camera_offset_changed": {
    	"Vector2": {
     	   "x": 200,
     	   "y": -400
    	}
	}
},

Doing that way, I let me translate the key to a real Godot supported type.

func _convert_value_to_type(type: String, value):
	match type:
		"Vector2":
			return Vector2(value["x"], value["y"])

	return value

json:timer (optional)

Can display a non-player controlled dialogue that will terminate itself after timer's value, he used for one unique dialogue. Value is in second.

Will not use the next value, can only show one dialogue at a time

  "001": {
    "name": "Player",
    "portrait": "Player",
    "text": {
      "en": "I can now double jump",
      "fr": "Je peux maintenant sauter une deuxieme fois"
    },
    "timer": 5
  }

Clone this wiki locally