Page 1 of 1
Accessing list of all conversation titles in a database
Posted: Wed Mar 20, 2019 8:23 pm
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
Re: Accessing list of all conversation titles in a database
Posted: Wed Mar 20, 2019 8:36 pm
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);
}
Re: Accessing list of all conversation titles in a database
Posted: Wed Mar 20, 2019 8:54 pm
by joeykid6
Excellent, Tony, thank you!
Re: Accessing list of all conversation titles in a database
Posted: Wed Mar 20, 2019 10:06 pm
by Tony Li
Glad to help!
Re: Accessing list of all conversation titles in a database
Posted: Wed Mar 20, 2019 11:37 pm
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?
Re: Accessing list of all conversation titles in a database
Posted: Thu Mar 21, 2019 12:07 am
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");