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
Accessing list of all conversation titles in a database
Re: Accessing list of all conversation titles in a database
Hi Joe,
If you're defining a script variable, you can use the [ConversationPop] attribute:
At runtime, read DialogueManager.masterDatabase.conversations:
If you're defining a script variable, you can use the [ConversationPop] attribute:
Code: Select all
[ConversationPopup]
public string conversationTitle;
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
Excellent, Tony, thank you!
Re: Accessing list of all conversation titles in a database
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:
Any idea why there would be an offset?
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);
}
Re: Accessing list of all conversation titles in a database
Nevermind! I fixed it. Just a typo. I was calling the prefab instead of the instance to find the text label.
should be
Code: Select all
var buttonLabel = buttonPrefab.transform.Find("Text");
Code: Select all
var buttonLabel = button.transform.Find("Text");