Confused About JSON paths

0 favourites
  • 4 posts
  • First of all, apologies for my lack of understanding of JSON. I'm not familiar with JavaScript. I've read and re-read the documentation as well as loads of other online resources but I still don't feel like anything has 'clicked' for me yet. With that said, here's my situation:

    I've been messing around trying to build a branching dialogue tool that uses json data. I've been using Dialogue Designer to generate the json files and jsonviewer.stack.hu to try and better understand the structure of json files.

    The issue I keep coming into is that each path node is classified by a number (starting from 0) and the actual data that would help me identify nodes and know which one to go to next is nested WITHIN these numbers.

    For example, to path to get to the first node is "0.nodes.0". From here, I can access all the details I need: the dialogue text, the character name, the node name and the choices - each one also containing the node name that picking that choice leads to.

    The issue I keep running into is that I can't use the node name under 'next' to get to the next node, because I still need to know which number (0,1,2,3,etc.) that node falls under. That's not information that is contained within the node.

    This way of formatting seems pretty standard across all dialogue editors (Articy, Chatmapper, Twine, etc.). How do people get around this and get a new path based on information that's actually inside the numbered nodes?

    I'd hugely appreciate any help. Especially if you could explain it simply. I don't know if it's useful or not but I'll link to the test file I'm using below. Currently, I'm just trying to use a text object and a simple test dialogue to debug this and figure out what I'm doing wrong - there's not much logic.

    drive.google.com/file/d/1Dh_RvwTxMYxbieIzYpLzCIodxqQYYmWS/view

  • I've never used Dialogue Designer or any similar editors. I'm guessing they are pretty powerful tools and allow to construct very complex dialogues, that's why the JSON structure is so cumbersome.

    You can edit or convert the JSON before importing it into your game. For example, you can straight away get rid of the parent array - remove "[" and "]" from the top and the bottom of JSON string. This way you won't have to add "0." to access any key.

    The "nodes" is still an array, so to find a particular dialogue you will have to iterate it, for example:

    For Each entry in "nodes"
    Compare two values JSON.Get(".node_name")="6291363"
    

    You can create a function for it, which will search the JSON for a particular dialogue id and return the path to it. For example:

    JSON Set Path to Functions.FindDialogueByID("6291363")
    MyText set text to JSON.Get(".text.ENG")
    

    As the result the text should show "Good for me? Absolutely right - I'm a dog!"

    Another option is to convert "nodes" array to a list of objects and maybe simplify JSON by removing all unused keys. You'll either have to do it manually or perhaps create a small tool for it. The resulting JSON may look like this:

    {
     "dialogue_dog": {
     "character": "Player",
     "choices": [],
     "text": "Hello, I'm a dog!"
     },
     "dialogue_dog_response1": {
     "character": "Player",
     "choices": [],
     "text": "Good for me? Absolutely right - I'm a dog!"
     }
    }
    

    This way you could access any dialogue directly by its key name without having to loop through the array. For example "dialogue_dog_response1.text"

    By the way, check out this demo, it shows paths to all keys in JSON:

    dropbox.com/s/srgf9lme08by9wa/JSON-RecursiveRead.c3p

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I've never used Dialogue Designer or any similar editors. I'm guessing they are pretty powerful tools and allow to construct very complex dialogues, that's why the JSON structure is so cumbersome.

    You can edit or convert the JSON before importing it into your game. For example, you can straight away get rid of the parent array - remove "[" and "]" from the top and the bottom of JSON string. This way you won't have to add "0." to access any key.

    The "nodes" is still an array, so to find a particular dialogue you will have to iterate it, for example:

    > For Each entry in "nodes"
    Compare two values JSON.Get(".node_name")="6291363"
    

    You can create a function for it, which will search the JSON for a particular dialogue id and return the path to it. For example:

    > JSON Set Path to Functions.FindDialogueByID("6291363")
    MyText set text to JSON.Get(".text.ENG")
    

    As the result the text should show "Good for me? Absolutely right - I'm a dog!"

    Another option is to convert "nodes" array to a list of objects and maybe simplify JSON by removing all unused keys. You'll either have to do it manually or perhaps create a small tool for it. The resulting JSON may look like this:

    > {
    "dialogue_dog": {
    "character": "Player",
    "choices": [],
    "text": "Hello, I'm a dog!"
    },
    "dialogue_dog_response1": {
    "character": "Player",
    "choices": [],
    "text": "Good for me? Absolutely right - I'm a dog!"
    }
    }
    

    This way you could access any dialogue directly by its key name without having to loop through the array. For example "dialogue_dog_response1.text"

    By the way, check out this demo, it shows paths to all keys in JSON:

    https://www.dropbox.com/s/srgf9lme08by9wa/JSON-RecursiveRead.c3p?dl=0

    Thanks for your help! I'll be honest, I didn't understand everything you said the first time reading it but I've read it a few times and now I think I at least understand some of it - mostly that the iterative process is the way to go.

    I'm still struggling to fully wrap my head around 'for each' but I've at least managed to make a start. Now I just need to figure out how to make the engine understand to go to 'next' when there are no choices (I tried calling the function again when the node-name is START or when option1 is 0 but no luck yet). I think I'm starting to get the logic, but getting to the point where I can think in JSON paths and understand the 'for each' stuff without making my head hurt may take a while.

    Here's the updated version with a slightly more complex dialogue if you're interested: drive.google.com/file/d/1EP7vfR_ieEZFvQK4ddW23VFguyzb2NnH/view

    My ultimate goal is to get the point where I can build a robust system to process dialogues that will parse any DD files I feed into it with a simple function so I can get on with the simple stuff like moving the character around and building the non-dialogue side of things.

    Thanks again for your help!

  • The JSON structure is really complex, I don't understand what half of the keys there are for. Is there a way to disable features which you are not using, so that they are not added to JSON?

    I made a few changes in your file, nothing major, just to show how to access any dialogue and how to iterate the list of choices:

    dropbox.com/s/rlfmwvidshi4o8e/DogDialogueTestTake3.c3p

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)