How to get conversation field by string

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Krejwen
Posts: 25
Joined: Mon Jun 08, 2020 8:09 am

How to get conversation field by string

Post by Krejwen »

Hi,

Is it possible to get custom Conversation Field by conversation title in C#?

In the documentation I see only a method:

GetConversationField()

which take converstation ID (int).

I cannot find anything that can help me to transtale Title into the ID.
Krejwen
Posts: 25
Joined: Mon Jun 08, 2020 8:09 am

Re: How to get conversation field by string

Post by Krejwen »

I have a temporary solution:

I save reference to database where conversation is and then I get the Conversation object. However, when I try go get my custom field "Tags" I get the following error:
Dialogue System: Lua code 'return Conversation[9].Tags' threw exception 'Lookup of field 'Tags' in the table element failed because the table element itself isn't in the table.'
All conversation have Tags field and all of them have unique ID. I am not able understand where is the problem...
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get conversation field by string

Post by Tony Li »

Hi,

If you're not making runtime changes, you can get the Tags field directly from the dialogue database using DialogueDatabase.GetConversation() to get a conversation by Title or ID:

Code: Select all

var conversation = DialogueManager.masterDatabase.GetConversation("Some Title");
string tags = conversation.LookupValue("Tags");
If you need to get the runtime value from Lua:

Code: Select all

var conversation = DialogueManager.masterDatabase.GetConversation("Some Title");
string tags = DialogueLua.GetConversationField(conversation.id, "Tags").asString;
Krejwen
Posts: 25
Joined: Mon Jun 08, 2020 8:09 am

Re: How to get conversation field by string

Post by Krejwen »

Hi,

Thanks for response.

What in case if I have many databases, e.g. DLC with additional content?
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get conversation field by string

Post by Tony Li »

Hi,

If you have multiple databases, you'll use Extra Databases to load additional databases into memory.

DialogueManager.masterDatabase will contain the content of all of the databases loaded into memory.
Krejwen
Posts: 25
Joined: Mon Jun 08, 2020 8:09 am

Re: How to get conversation field by string

Post by Krejwen »

Hi,

Thanks for info. It solve my problem!

I check in the documentation that there is info that MasterDatabase fields contains all data. However, I suggest to add this info into "Standard documentation" e.g. in the section "Working With Multiple Databases/Extra Databases".

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

Re: How to get conversation field by string

Post by Tony Li »

Good idea! Will do.
Post Reply