Page 1 of 1

Easy way to have alternate dialogue node text when you return to the node?

Posted: Tue Mar 26, 2019 8:35 pm
by RickSaada
I've been mocking up a simple text adventure like dialogue, where you get a room description from the "NPC" and then pick where you go next. Typically, when you go back to a room you've visited in these kinds of games you get a shorter version of the description. I'm wondering if there's an easy way to do this kind of thing that I'm missing.
So far what I've done is make a group node for each room, with two child nodes off of it, one with a conditional testing a visited variable for false, the other for true. The false version gives you the long version of the description and sets the visited variable for that node. The true version gives you the short version of that room's description. They then both link to all the choices for where you can go from there.

This all works, but it requires me to have three nodes and a variable for every location, which seems excessive. Is there some way via markup to test a variable and present one of two sets of text based on that? Then I could collapse all that into a single node that presents the full text if the variable isn't set, and then sets it so that the next time that node is visited it uses the short version.

I've also looked at using the simstatus to handle the visited/presented checks, but keeping those around for every conversation just to handle the few that might want to do this also seems like overkill.
What I'd really want is a per-conversation & only keeping simstatus while that conversation is running kind of thing, which is basically what I've written myself via variables. It also seems like if I need a variable for every node in every conversation I'd end up with an amazing clutter of global variables, most of which would only pertain to a single conversation. Is there a concept of conversation local state that I'm missing?

Thanks,

Rick

Re: Easy way to have alternate dialogue node text when you return to the node?

Posted: Tue Mar 26, 2019 9:21 pm
by Tony Li
There isn't anything built in, but a small script should do the trick. Here's an example:

VerboseBriefExample_2019-03-26.unitypackage

It splits the text on "::", which is an arbitrary string I made up for this example. Anything before "::" is the verbose text. Anything after is the brief text.
VerboseBriefConversations.cs

Code: Select all

using PixelCrushers.DialogueSystem;
using System.Collections.Generic;
using UnityEngine;

public class VerboseBriefConversations : MonoBehaviour
{

    public string splitOn = "::";
    public bool alwaysVerbose = false;

    HashSet<int> visited = new HashSet<int>();
    string[] separators;

    private void Awake()
    {
        separators = new string[] { splitOn };
    }

    void OnConversationStart(Transform actor)
    {
        visited.Clear(); // Start fresh with each conversation.
    }

    void OnConversationLine(Subtitle subtitle)
    {
        // Try to split the text into verbose and brief:
        string[] texts = subtitle.formattedText.text.Split(separators, System.StringSplitOptions.None);
        if (texts.Length >= 2)
        {
            // Show verbose text if first time; otherwise brief text:
            bool verbose = !visited.Contains(subtitle.dialogueEntry.id) || alwaysVerbose;
            subtitle.formattedText.text = verbose ? texts[0] : texts[1];
            // Then mark entry as visited:
            visited.Add(subtitle.dialogueEntry.id);
        }
    }
}

Re: Easy way to have alternate dialogue node text when you return to the node?

Posted: Wed Mar 27, 2019 4:36 pm
by RickSaada
Cool! So just to be sure I understand, I can drop that script on my dialog manager object or on the actor, and it catches OnConversationLine, letting me tweak the line as needed?

Re: Easy way to have alternate dialogue node text when you return to the node?

Posted: Wed Mar 27, 2019 4:50 pm
by RickSaada
Dropped it on my DialogManager object and it works like a charm! Thanks for the help. My conversation graph is now far easier to understand :D

Re: Easy way to have alternate dialogue node text when you return to the node?

Posted: Wed Mar 27, 2019 7:42 pm
by Tony Li
Glad to help!