Accessing Dialogue Entry Fields

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
snailBerry
Posts: 4
Joined: Mon Feb 07, 2022 5:15 pm

Accessing Dialogue Entry Fields

Post by snailBerry »

Hey! I want to add quotes from conversations to a List<string> in a separate script. I was planning on using the "Dialogue Text" field under the dialogue entry, but I can't find a good way of accessing it.

Basically I want the loop to go as such:
-player talks to character
-player gets to specific line of dialogue
-that line is saved to a list of special quotes

I feel like there's a lua command I'm missing or something. I'll take any help.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing Dialogue Entry Fields

Post by Tony Li »

Hi,

You could use a script like the one below. It registers a Lua function RecordQuote(). Since dialogue entry Script fields run before OnConversationLine, it sets a bool so OnConversationLine knows to add the line to the list.

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class Quotes : MonoBehaviour
{
    bool quoteThisLine = false;
    
    List<string> quotes = new List<string>();

    void Awake()
    {
        Lua.RegisterFunction(nameof(RecordQuote), this, SymbolExtensions.GetMethodInfo(() => RecordQuote()));
    }

    void RecordQuote()
    {
        quoteThisLine = true;
    }

    void OnConversationLine(Subtitle subtitle)
    {
        if (quoteThisLine) 
        {
            quotes.Add(subtitle.formattedText.text);
            quoteThisLine = false;
        }
    }
}
snailBerry
Posts: 4
Joined: Mon Feb 07, 2022 5:15 pm

Re: Accessing Dialogue Entry Fields

Post by snailBerry »

This is great! thank you! I just have a small follow up question.

I understand that I would use the RecordQuote() function on dialogue nodes that I want to save to the quotes list.
I don't know where to implement the OnConversationLine(Subtitle subtitle) function. I also dont know what to pass into the subtitle variable.

Any extra help would be awesome. I'm super new to the dialogue system.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing Dialogue Entry Fields

Post by Tony Li »

Sorry, I completed skipped over that part, didn't I.

Put the script on your Dialogue Manager GameObject. If it's on the Dialogue Manager, the Dialogue System will automatically call the OnConversationLine() method.
Post Reply