Branching Dialogue using JSON

15

Index

Features on these Courses

Attached Files

The following files have been attached to this tutorial:

.c3p

branching-dialogue.c3p

Download now 170.7 KB

Stats

8,538 visits, 19,345 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 7 Apr, 2020. Last updated 21 Apr, 2022

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.

  • 10 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Hi!

    I started an open source Game Dialogue Maker project (still very much in alpha) based on this very tutorial. The idea is to offer a node-based system of planning branching dialogue and then you can export it to a JSON file that you can drop to your c3p project here. Everything is in JavaScript and HTML. You can check it out here (and contributors are very welcome):

    github.com/AnttiPerala/GameDialogueMaker

    I don't understand some things in the example JSON perfectly yet. For example the very first object that sets nextscene to 3. If I leave it out from the output of Game Dialogue Maker then it breaks so it seems necessary. But why is it setting nextscene to 3? Can you Laura_D expand on that part?

  • Hi Laura_D,

    To activate a function, a "Z" press is needed, is there a way to have the function activate simultaneously with a dialogue line?

    RESOLVED EDIT

    For people interested, you can make a new type "lineFunction" and call a line and a function at the same time.

  • Great tutorial, thanks!

  • Hey, thank you for tutorial, i use Construct 2 and Construct 3!

  • Hi, Laura_D I have a major issue I've been trying to solve. I haven't been able to figure it out. If you could help me out that'd mean a ton.

    construct.net/en/forum/construct-3/how-do-i-8/change-variable-per-copy-169181

  • Load more comments (5 replies)