Querying the Dialogue Database

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
UKMasters
Posts: 15
Joined: Sun Jun 28, 2020 3:41 pm

Querying the Dialogue Database

Post by UKMasters »

Hi Tony,

Some more newbie questions, this time about the Dialogue Database.

How would I query the Dialogue Database using a c# script?
For example, I want to be able to loop through all the Conversations in the database and get their ID, Title and other key information about each Conversation.

I then want to use this information to populate a separate set of tables / lists that will control game logic. For example, keeping track of which Conversations (stories in my game) that a Player has seen, changing the likelihood that a story will be presented to the player based on the current game state, etc (I can't use conditions for this as it's quite complex).

Second question: Is it possible to associate Conversations with Locations, Quests, Items, etc?
E.g. Conversation number 1 would be associated with Location 3, Conversation number 2 would also be associated with Location 3 (because Location 3 is a Forest and both Conversations take place in a forest).

If you could provide me some guidance on getting started, I hope I will be able to muddle my way through from there!

Thanks

Pete
UKMasters
Posts: 15
Joined: Sun Jun 28, 2020 3:41 pm

Re: Querying the Dialogue Database

Post by UKMasters »

I think for question 1, I can do something like...

Code: Select all

        for (int i = 1; i < 50; i++)
        {
            var conversationTitle = DialogueManager.masterDatabase.GetConversation(i);
            string title = conversationTitle.Title;
            Debug.Log("Story name is " + title);
        }
But please let me know if I'm missing something, or if there is a better way.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Querying the Dialogue Database

Post by Tony Li »

Hi Pete,
UKMasters wrote: Tue Aug 18, 2020 7:20 pmHow would I query the Dialogue Database using a c# script?
DialogueManager.masterDatabase.conversations. Example:

Code: Select all

foreach (var conversation in DialogueManager.masterDatabase.conversations)
{
    Debug.Log($"Title={conversation.Title}, ID={conversation.id}");
}
UKMasters wrote: Tue Aug 18, 2020 7:20 pmSecond question: Is it possible to associate Conversations with Locations, Quests, Items, etc?
E.g. Conversation number 1 would be associated with Location 3, Conversation number 2 would also be associated with Location 3 (because Location 3 is a Forest and both Conversations take place in a forest).
Yes. You can add a custom field and set its type to Location:

conversationField.png
conversationField.png (34.2 KiB) Viewed 711 times

To access that field:

Code: Select all

var conversation = DialogueManager.masterDatabase.GetConversation("Example Conversation");
locationID = conversation.LookupInt("Setting");
var location = DialogueManager.masterDatabase.GetLocation(locationID);
UKMasters
Posts: 15
Joined: Sun Jun 28, 2020 3:41 pm

Re: Querying the Dialogue Database

Post by UKMasters »

Hi Tony,

Thanks for the reply above and for all your help.

I see how I can add a custom field to a specific conversation, but what I need to do is to "extend" the datamodel for EVERY conversation to include additional fields.

For example, I want to store the following bits of additional information against every conversation:
  • location
  • specificlocation
  • music
  • backgroundpicture
(this list is incomplete, so I would like to know how to extend the datamodel).

Related to the above, we are planning to use Twine to create the conversations and then we'll load them into Dialogue System. As part of this, would it be feasible to read data from the Twine file (e.g. tags) and populate the fields above? Could you advise how this could work please?

Thanks
Pete
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Querying the Dialogue Database

Post by Tony Li »

Hi Pete,

Extend the data model by adding fields (location, specificlocation, etc.) to the dialogue database's template.

Fields in the template will be added to any conversations added by the Twine importer. If you use the Dialogue Editor to set the values of those fields, subsequent imports using the Twine importer will not overwrite the values that you've set.

However, the Twine importer will not import values for those fields from Twine files. If you want to do that, you'll need to add your own code. To add your own code, I recommend:

1. Make a subclass of TwineImporter. Its methods are virtual, so you can override them to add any additional functionality you need.

2. Make a TwineImportWindow that uses your subclass instead of TwineImporter.
Post Reply