In this system, I’m defining Event Dialogue as dialogue that bridges an event – in this case, a ‘battle’ with an NPC. So, the idea is that you speak to an NPC, you ‘battle’ (in this case a simple layout switch) then when that’s done, the NPC says something totally different. This is achieved by using the nextscene key in the dialogue file.
Let’s start by looking at what this key does in standard dialogue. In the same way that when the Z key is pressed we check the type to see if a line or a function is being called, when the EndDialogue function is called we now check to see if the current scene has a key called nextscene and if it does, we change the SceneID on the NPC we’re interacting with to match the value of nextscene.
This means, the next time we speak to that NPC, it’ll say something different. In the example project, you can see this in action with the first NPC, the one who asks you the question.
So, in the case of the ‘battle’, when you speak to the NPC (the furthest right in the example project) we see the initial lines of dialogue as the NPC challenges the player. Then the layout changes, and when we return, the NPC says something different. This is till done with the nextscene key but it’s treated slightly differently.
This is because in the JSON file, the lines associated with the trainer do not have an end key to close the dialogue. It’s replaced by fight. When the dialogue system comes across a fight key, rather than calling the EndDialogue function, it calls the NPCFight function to trigger the start of the ‘battle’. To make sure that the NPC still says something different when we return to them, the SceneID change is added to the start of the NPCFight function:
Now, when you return to the main layout, the NPC will say its next line – that’s scenes 1 and 12 in the example. The nextscene key is a great way of creating chains of dialogue so your characters can say multiple sets of lines without having to store lots of IDs as instance variables.