Welcome to another tutorial regarding the use of JSON for NPC-based dialogue. This tutorial uses the same project as the Using a JSON Dialogue System with NPCs tutorial, however, it’s been extended to showcase some additional, more advanced functionality.
Starting with what’s changed in the layout of the project, you’ll see that there are now three NPC objects. The new addition will be used to demonstrate calling a function using the JSON file.
Talking of the JSON file, that’s had a few changes made to it too. There’s now an additional key in the array for each dialogue called “type” – this determines the type of line to be displayed, be it a function, timeline or just a regular line so that the correct functions can be called.
Each dialogue contains an ID number, (attached to the NPC to call the correct lines) and an array which itself contains the dialogue data including the character’s name, dialogue type and of course the dialogue text itself.
If you take a look through the JSON file, you’ll see there are a few things that look a bit like BBCode tags, only with curved brackets instead of square ones. That’s because square brackets are already used to denote Arrays within JSON, so we need to use a function to apply the necessary formatting.