Accessing list of all conversation titles in a database

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
joeykid6
Posts: 17
Joined: Thu Feb 07, 2019 1:57 pm

Accessing list of all conversation titles in a database

Post by joeykid6 »

Hi Tony and all,

I'd like to provide an interface to developers that lets them start any conversation in the database from a dropdown list (or something similar). I'd prefer to pull all current conversation titles directly from the database dynamically, so I don't have to update when the data changes. I can't seem to find a method in the API that lets me do this. Any thoughts?

Best,
Joe
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing list of all conversation titles in a database

Post by Tony Li »

Hi Joe,

If you're defining a script variable, you can use the [ConversationPop] attribute:

Code: Select all

[ConversationPopup]
public string conversationTitle;
At runtime, read DialogueManager.masterDatabase.conversations:

Code: Select all

using PixelCrushers.DialogueSystem;
...
foreach (var conversation in DialogueManager.masterDatabase.conversations)
{
    Debug.Log(conversation.Title);
}
joeykid6
Posts: 17
Joined: Thu Feb 07, 2019 1:57 pm

Re: Accessing list of all conversation titles in a database

Post by joeykid6 »

Excellent, Tony, thank you!
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing list of all conversation titles in a database

Post by Tony Li »

Glad to help!
joeykid6
Posts: 17
Joined: Thu Feb 07, 2019 1:57 pm

Re: Accessing list of all conversation titles in a database

Post by joeykid6 »

Ok, so only one small oddity. I decided to use buttons, and the title and button event are offset by one. In other words, the button that has the text title for conversation 5 is playing conversation 6. They're being assigned in the foreach loop, so the conversation data should be identical. Here's the whole loop:

Code: Select all

        foreach (var conversation in DialogueManager.masterDatabase.conversations)
        {
            var button = Instantiate(buttonPrefab);
            var buttonLabel = buttonPrefab.transform.Find("Text");
            var buttonLabelText = buttonLabel.gameObject.GetComponent<Text>();
                                 
            button.onClick.AddListener(() => DialogueManager.StartConversation(conversation.Title));
            buttonLabelText.text = conversation.Title;

            button.transform.SetParent(transform);
        }
Any idea why there would be an offset?
joeykid6
Posts: 17
Joined: Thu Feb 07, 2019 1:57 pm

Re: Accessing list of all conversation titles in a database

Post by joeykid6 »

Nevermind! I fixed it. Just a typo. I was calling the prefab instead of the instance to find the text label.

Code: Select all

var buttonLabel = buttonPrefab.transform.Find("Text");
should be

Code: Select all

var buttonLabel = button.transform.Find("Text");
Post Reply