Using a JSON dialogue system with NPCs

13

Index

Features on these Courses

Attached Files

The following files have been attached to this tutorial:

.c3p

basicjsondialogueexample.c3p

Download now 167.69 KB

Stats

7,236 visits, 14,883 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 11 Dec, 2019.

Currently, this dialogue system is usable, but there are a few things that could be improved. For example, the player can wander about while talking to an NPC. And it might be nice to have a button to automatically load all of the text rather than wait for typewriter to finish.

Let’s start with keeping the player in position while dialogue is running. This is very simple to do – we just need to enable/disable the TileMovement behaviour based on the value of the GameState variable:

Condition

System ▶︎ GameState = “”

Action

Player ▶︎ Set TileMovement Enabled

Condition

System ▶︎ GameState = “Dialogue”

Action

Player ▶︎ Set TileMovement Disabled

So, now that the player can’t move while talking to an NPC, let’s look at tweaking the dialogue itself slightly. The first thing we’ll add is a sprite that appears once the typewriter text has finished signifying that you can progress the dialogue. The sprite can be called and look like whatever you like, I’ve just used a small arrow icon called ContinueDialogue:

Condition

NPCTextBox ▶︎ On typewriter text finished

System ▶︎ GameState = “Dialogue”

Action

ContinueDialogue ▶︎ Set to Visible

If you make sure the object is initially set to invisible when you add it to the dialogue layer, it should only appear when the text has finished displaying. This makes it a nice indicator to the player that they can press Z to continue.

The last tweak we’ll add is to allow the player to press a button to quickly load all the text in a line. This may be more comfortable to use on a gamepad, but it works perfectly well on keyboard:

Condition

Keyboard ▶︎ On X key pressed

Sub-event Condition

Sub-event level: A

Player ▶︎ Is overlapping NPC at offset (8,0)

OR

Player ▶︎ Is overlapping NPC at offset (-8,0)

OR

Player ▶︎ Is overlapping NPC at offset (0,8)

OR

Player ▶︎ Is overlapping NPC at offset (-8,0)

Sub-event Condition

NPCTextBox ▶︎ Is typewriter text running

Sub-event Action

NPCTextBox ▶︎ Finish typewriter

This will immediately finish the typewriting effect and display all the text at once. The player still needs to press Z to carry on to the next line, but you could probably add something to the nested event block for Z key control to change that if you wanted to.

And that’s all for this tutorial! Hopefully, you understand how to implement a basic JSON dialogue system a bit now.

Happy Developing!

  • 3 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Thanks so much! This helped me out a ton!

  • Thanks so much for making this, I couldn't have done it on my own, but now I understand.

    Also a lot more elegant and flexible than some other solutions out there, good work

  • I'll take a look at this compared to my current XML implemenation of the Dialog system. Looks pretty similar in scope, but the ability to call in fuctions via dialogues to effect the entire game would be quite handy like allowing for the player to choose their own name.