The first thing you’ll notice is that the NPC system is substantially larger in this project. That’s because this was born out of a need to refactor my own NPC code used in my main game file. I could have taken it out, but I’ve left it there as an example of using families etc.
The basics of the NPC mechanics were designed a LONG time ago, and quite frankly were pretty messy. They worked, but there was a lot of event repetition and the whole thing was bulkier than it needed to be. It was fine for showing how each NPC worked as in this tutorial but not great for a big game. So if you’re looking to polish your skills refactoring and using families, why not try taking the NPC events from the original tutorial, and tidying them up to something more like what’s included in this tutorial.
Anyway, tangents aside, let’s get back to the project at hand.
The project uses a lot of the same JSON functionality as the previous project. So, you’ve still got the CurScene, CurDialogue and GameState global variables, but there are some extra ones needed for this project:
- InteractionID – This stores the ID number of the NPC being talked to, helps with picking
- Question – a Boolean which tells the game whether or not a question is being displayed
- ChosenAnswer – This stores the ID number of the answer currently selected by the player
- CurLine – Simply used for debugging, this shows the current line of text being pulled from the JSON file
In terms of events a lot of what we’ll be using expands upon the events in the previous project. There will be a few more functions, and some changes to existing ones, but we’ll cover that as we go along.
The JSON file has changed a little in structure, adding some different strings for the type key to allow the system to perform End checks. By having “end” as a type in the JSON, we no longer need the GetNumLines function, because any time the type reads as “end” the EndDialogue function will be called.