Ways to display new unlocked dialogue lines + ending bark on dialogue start

Announcements, support questions, and discussion for the Dialogue System.
KayVen
Posts: 13
Joined: Mon Apr 12, 2021 1:58 am

Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by KayVen »

Heyo!
My goal is to visually show the player that the NPC has dialogue lines that the player hasn't seen yet. I'm using DS with Adventure creator, in case it's important.
I am thinking that it could be done with some kind of a variable that would be false in default for not-yet-heard lines, and display an icon above an NPC if it has any such false variables, but I doesn't seem very effective :c It would also be neat to highlight unheard dialogue options in response menus, if possible! Is there a way to go about this?

Small bonus question :D Is there a way to interrupt a bark on the conversation start? I have barks disabled in conversations, but when I start one, it doesn't interrupt a current bark, if it's happening.

Thank you!
User avatar
Tony Li
Posts: 21989
Joined: Thu Jul 18, 2013 1:27 pm

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by Tony Li »

Hi,
KayVen wrote: Sat Apr 24, 2021 4:15 amMy goal is to visually show the player that the NPC has dialogue lines that the player hasn't seen yet. I'm using DS with Adventure creator, in case it's important.
I am thinking that it could be done with some kind of a variable that would be false in default for not-yet-heard lines, and display an icon above an NPC if it has any such false variables, but I doesn't seem very effective :c
You'll almost certainly want to use a script for this. Maybe something roughly like this:

Code: Select all

public class NewDialogueIndicator : MonoBehaviour
{
    public SpriteRenderer indicator; // Assign in inspector.
    public List<string> variables; // Assign in inspector;
    
    void OnStart() { CheckVariables(); }    
    void OnConversationStart(Transform actor) { indicator.enabled = false; }
    void OnConversationEnd() { CheckVariables(); }
    
    void CheckVariables()
    {
        indicator.enabled = false;
        foreach (string variable in variables)
        {
            if (DialogueLua.GetVariable(variable).asBool == false)
            {
                indicator.enabled = true;
                break;
            }
        }
    }
}
KayVen wrote: Sat Apr 24, 2021 4:15 amIt would also be neat to highlight unheard dialogue options in response menus, if possible! Is there a way to go about this?
On the Dialogue Manager GameObject, tick Other Settings > Include Sim Status. Then set Input Settings > [em#] Tag For Old Responses. This will wrap heard dialogue options in an emphasis tag (e.g., darkened, or italics, etc.). You can edit the emphasis tag appearance on the Dialogue Editor's Database page.
KayVen wrote: Sat Apr 24, 2021 4:15 amSmall bonus question :D Is there a way to interrupt a bark on the conversation start? I have barks disabled in conversations, but when I start one, it doesn't interrupt a current bark, if it's happening.
You can use the script in this post.
KayVen
Posts: 13
Joined: Mon Apr 12, 2021 1:58 am

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by KayVen »

Thanks Tony!

You'll almost certainly want to use a script for this.
I've tried to attach the script you've mentioned, but I am getting this error and I'm not sure where to go from here. Apologies if it's a noobie question, I'm mostly doing things by trial and error when it comes to scripting :?

So the script looks like this right now:

Code: Select all

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

public class NewDialogueIndicator : MonoBehaviour
{
    public Sprite indicator; // Assign in inspector.
    public List<string> variables; // Assign in inspector;

    void Start() { CheckVariables(); }
    void OnConversationStart(Transform actor) { indicator.enabled = false; }
    void OnConversationEnd() { CheckVariables(); }

    void CheckVariables()
    {
        indicator.enabled = false;
        foreach (string variable in variables)
        {
            if (DialogueLua.GetVariable(variable).asBool == false)
            {
                indicator.enabled = true;
                break;
            }
        }
    }
}
And I am getting this error:

Code: Select all

Assets\NewDialogueIndicator.cs(17,19): error CS1061: 'Sprite' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'Sprite' could be found (are you missing a using directive or an assembly reference?)
Do you know what to do about it? I figured there's a definition of Sprite for 'enabled' needed, but I have no idea how to do that.
Thanks again and sorry for noobie questions!
User avatar
Tony Li
Posts: 21989
Joined: Thu Jul 18, 2013 1:27 pm

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by Tony Li »

I meant to type "SpriteRenderer", not "Sprite". I fixed my original code above. A Sprite is an actual image asset. A SpriteRenderer is a component in the scene that displays a Sprite. You'll want to enable and disable the SpriteRenderer that the NPC uses for its indicator.
KayVen
Posts: 13
Joined: Mon Apr 12, 2021 1:58 am

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by KayVen »

A-ha, I see!
Yes, that works, thank you! I've tried playing around with it and it seems quite close to what I wanted to achieve, but I think it's still above my capabilities. Seems like I won't be able to dodge learning how to script either way :D
But thanks Tony! The other issues (bark and highlighting used dialogue options) worked well, just need to figure out this last one ^^
User avatar
Tony Li
Posts: 21989
Joined: Thu Jul 18, 2013 1:27 pm

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by Tony Li »

What part of it isn't working the way you want?
KayVen
Posts: 13
Joined: Mon Apr 12, 2021 1:58 am

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by KayVen »

Sorry, I figured that I would have to read more documentation in the future, to understand the problem properly :)
Well, I am not entirely sure what to do with variables. I assumed that I will create a variable that will be checked by the script, assign it in the inspector, and then somehow use it in the dialogues? I thought that it probably should be a default sequencer command so I wouldn't have to do it manually for every dialogue line, maaaybe?

When I tested it I made a gameobject with the SpriteRenderer as a child for an NPC gameobject, but I realized that I can assign only one SpriteRenderer at a time. Is there a way to have that dynamically for every NPC in the scene?
User avatar
Tony Li
Posts: 21989
Joined: Thu Jul 18, 2013 1:27 pm

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by Tony Li »

Hi,

I assumed you would define specific variables in the Dialogue Editor's Variable section. And then in the conversation's dialogue entries' Script fields you would set the variables true. (See the Conversation Conditions tutorial for more info about setting variables.)

If, instead, you want to automatically track every single line of dialogue without manually managing variables, you could turn on SimStatus and change the script to check the SimStatus values of all of the dialogue entries in a conversation. I don't think it would work to automatically apply it to every NPC in the scene because each NPC will presumably be assigned a different conversation.

Code: Select all

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

public class NewDialogueIndicator : MonoBehaviour
{
    [ConversationPopup] public string conversationTitle;
    public SpriteRenderer indicator;

    void Start() { CheckSimStatus(); }
    void OnConversationStart(Transform actor) { indicator.enabled = false; }
    void OnConversationEnd() { CheckSimStatus(); }

    void CheckSimStatus()
    {
        indicator.enabled = false;
        var conversation = DialogueManager.masterDatabase.GetConversation(conversationTitle);
        if (conversation == null) return;
        foreach (DialogueEntry entry in conversation.dialogueEntries)
        {
            if (DialogueLua.GetSimStatus(entry) == DialogueLua.Untouched)
            {
                indicator.enabled = true;
                break;
            }
        }
    }
}
Then add a child GameObject to one NPC. Add a SpriteRenderer component and the script above. Drag this child GameObject into the Project view to turn it into a prefab. Then you can add the prefab to all of your other NPCs.

Then inspect each NPC's instance of the prefab, and select the NPC's conversation from the dropdown menu.
KayVen
Posts: 13
Joined: Mon Apr 12, 2021 1:58 am

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by KayVen »

Making a custom variable and use it in the scripts field was my initial thought, but it seemed like there would be more automated way to go about this :) Plus I wasn't sure how to check the variables without having to create variables for every simple dialogue path, so I got a bit lost. Hence I thought that I didn't really understand the issue and should read more documentation to be able to grasp it properly :)

However, the solution with the SimStatus sounds great! I went ahead and implemented it, however I got two errors:

Code: Select all

Assets\NewDialogueIndicator.cs(11,20): error CS0103: The name 'CheckSimStatus' does not exist in the current context

Code: Select all

Assets\NewDialogueIndicator.cs(20,41): error CS1579: foreach statement cannot operate on variables of type 'Conversation' because 'Conversation' does not contain a public instance definition for 'GetEnumerator'
I'm not sure what I overlooked :(
User avatar
Tony Li
Posts: 21989
Joined: Thu Jul 18, 2013 1:27 pm

Re: Ways to display new unlocked dialogue lines + ending bark on dialogue start

Post by Tony Li »

I fixed a couple of typos. I'm typing these suggested scripts straight into replies here, so let me know if there are any other compiler warnings.

I just tested the script as it is above, and it works fine.

One caveat: It checks every single node. If a conversation branches based on conditions, it's possible that some nodes will never be used. For example, say a conversation branches based on whether the player is a boy or a girl. One branch will never be used, so the script will always keep the indicator visible. If this could apply to your project, you might want to use variables instead. It's more work to explicitly set variables, but you have greater control of how the indicator gets checked.
Post Reply