Search Unity

Best dialogue system for me

Discussion in '2D' started by Jejkobb, Aug 10, 2017.

  1. Jejkobb

    Jejkobb

    Joined:
    Aug 10, 2017
    Posts:
    19
    Hi,
    I'm a programmer, I've been doing it a long time to make games. I started with actionscript in flash and now I'm trying to learn unity and C#. I'm making a story driven game and the game needs dialogue with choices that lead to different dialogue. By that I mean you'll be talking to one NPC and he'll say something, then you choose what to say back to him. What you choose to say doesn't have any difference in the story. It's mainly like Puzzle Agent where you ask questions to learn more about where you are and where you're going, and a lot of jokes.

    Well what I have now is, you can walk around and examine things. When you examine something it sends a string[] to my "dialogue" function which puts text on the screen and sounds and makes the characters mouth move. What I'm missing is dialogue with choices that lead to different answers. This is what my dialogue script looks like in the inspector:



    If the sentence starts with '=' my program knows it's the NPC talking, if the sentence starts with '+' it knows it's the player talking. All I want is an asset or a program which I can put in a string[] which sends it off to my function and when my function is done it'll go back and check if there are choices, if there are choices it'll make buttons for me with my font and when the player chooses one it'll send a string[] to my function again and it'll loop until the dialogue is done.

    I tried it on my own but nodes are very confusing to me since I haven't done anything like that before. I have never gone to any programming school so I'm not the best programmer either.

    English isn't my first language and I don't know if I did a good job explaining, please tell me if there's any more information you need to help me.
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    I think you're better off making a Dialogue class that includes all of this information (text, character, choices-- if you are using character portraits in your dialogue box you can specify that here, too). Check here if you're iffy on making classes.

    You can predefine every parameter in every bit of dialogue, and change the function in your dialogue script to accept a Dialogue[] object rather than a string[] and change behavior accordingly.
     
    Jejkobb likes this.
  3. Jejkobb

    Jejkobb

    Joined:
    Aug 10, 2017
    Posts:
    19
    Can you or someone please explain how I get information from nodes. For example:




    How do I get the dialogue from the first response? I don't understand. It's not like an array right? I can't just do this "node[0][0].dialogue[0]" and get the dialogue from the first response... I tried googling it but I can't find anything.
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Looks like it would probably be: "node.responses[0].dialogue[0]"
     
    Jejkobb likes this.
  5. Jejkobb

    Jejkobb

    Joined:
    Aug 10, 2017
    Posts:
    19
    Oh, that makes sense. Thanks for the quick response!!
    Also what is this about?

     
  6. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    I'd probably refactor the dialog system a little with custom editors, possibly even ScriptableObjects. An NPC should have a selection of initial question/statement nodes the player can pick (questions, insults, information, handing in quest items), and each would then lead to another node which triggers responses and/or actions. So the nodes also need the option for arbitrary code to execute, for example by linking methods similarly to the GUI events in Unity.

    I'd at least look at Fungus to see how they did it. I'm not sure if it also has a quest system integrated now, but it supports a lot of interesting things for conversations or just plain cut-scenes. There's even a Lua interpreter now, which can be a relief for simple scripting of this sort of thing.
     
    Jejkobb likes this.
  7. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Right now you have a dialogue and responses, and inside those responses you have more dialogues and more responses, inside those responses, more responses, etc, etc, to infinity. Unity will try to store the value even if it's null, so those nested references of the same type would create a tree of null values that never ends. So instead it limits that to 7 levels. I believe other systems in Unity depend on that behavior, which is why it must remain that way.

    You can read more in this thread here:
    http://answers.unity3d.com/questions/891985/getting-rid-of-serialization-depth-limit-exceeded.html

    Also google it, there's a lot of discussion and workarounds out there.
     
  8. Jejkobb

    Jejkobb

    Joined:
    Aug 10, 2017
    Posts:
    19
    So I can't exceed 7?
     
  9. Jejkobb

    Jejkobb

    Joined:
    Aug 10, 2017
    Posts:
    19

    Sorry for asking so much, but how do I reach the response of a response? In a node that is.



    I know how to reach "Hey Bill". Which is node.responses[0].dialogueText
    But I don't know how to reach the responses inside that response. Thanks so much for helping.
     
  10. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    If you're seeing that depth warning, you'll probably need to change your data structure so that it's not all nested.

    To access that would be "node.responses[0].responses[0].dialogueText[index]".