Beginner's question about dialogue Fields and C#
Beginner's question about dialogue Fields and C#
Hello!
I have a beginner's question and I don't know if I'm in the right place.
I'm trying to access custom fields in the dialogue current entry from a C# script.
But I can't find a method (neither from DialogueLua nor from DialogueManager) to access this information.
It should be easy, but I can't find it.
Anything I can think of?
Thank you!
I have a beginner's question and I don't know if I'm in the right place.
I'm trying to access custom fields in the dialogue current entry from a C# script.
But I can't find a method (neither from DialogueLua nor from DialogueManager) to access this information.
It should be easy, but I can't find it.
Anything I can think of?
Thank you!
Re: Beginner's question about dialogue Fields and C#
Hi Alain,
(I'm just copying my reply from the Unity forum. Either place is fine to ask questions.)
When you create content in the Dialogue Editor window, it's added to a dialogue database asset. At runtime, the Dialogue System loads the dialogue database content into an in-memory dialogue database called DialogueManager.masterDatabase, which should be considered static and read-only. It also copies certain info that can change during play -- such as Actors, Quests, and Variables -- into the Dialogue System's runtime Lua environment, which is read-write. Use DialogueLua to access the Lua values.
To read a field from any arbitrary dialogue entry, access it through DialogueManager.masterDatabase. For example:
When a conversation is active, the current conversation state is always accessible through DialogueManager.currentConversationState. This includes the current dialogue entry:
The Dialogue System has a number of C# event hooks and script messages (reference). One of these messages is OnConversationLine(Subtitle), which you can also use to work with the current dialogue entry:
(I'm just copying my reply from the Unity forum. Either place is fine to ask questions.)
When you create content in the Dialogue Editor window, it's added to a dialogue database asset. At runtime, the Dialogue System loads the dialogue database content into an in-memory dialogue database called DialogueManager.masterDatabase, which should be considered static and read-only. It also copies certain info that can change during play -- such as Actors, Quests, and Variables -- into the Dialogue System's runtime Lua environment, which is read-write. Use DialogueLua to access the Lua values.
To read a field from any arbitrary dialogue entry, access it through DialogueManager.masterDatabase. For example:
Code: Select all
DialogueEntry entry = DialogueManager.masterDatabase.GetDialogueEntry(conversationID, entryID);
string customFieldValue = Field.LookupValue(entry.fields, "My Custom Field");
Code: Select all
DialogueEntry currentDialogueEntry = DialogueManager.currentConversationState.subtitle.dialogueEntry;
Code: Select all
void OnConversationLine(Subtitle subtitle) // Called when the conversation gets to a dialogue entry.
{
string fieldValue = Field.LookupValue(subtitle.dialogueEntry.fields, "My Custom Field");
Debug.Log("Current line's 'My Custom Field' value is: " + fieldValue;
}
Re: Beginner's question about dialogue Fields and C#
Thank you for your quick answer!
I must be really stupid but there are no such methods appearing in the Visual Studio "Smart typing tool".
I declarerd the following:
using Language.Lua;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;
But the C# don't show me any specific method (No OnConversation... or anything else) and the "Field" class is declared ambiguous beetween LUA and Dialogue Manager (I don't know if I make myself clear...)....
Well, must be a rookie issue, sorry to take your time...
I must be really stupid but there are no such methods appearing in the Visual Studio "Smart typing tool".
I declarerd the following:
using Language.Lua;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;
But the C# don't show me any specific method (No OnConversation... or anything else) and the "Field" class is declared ambiguous beetween LUA and Dialogue Manager (I don't know if I make myself clear...)....
Well, must be a rookie issue, sorry to take your time...
Re: Beginner's question about dialogue Fields and C#
Hi,
You can remove "using Language.Lua".
Messages like OnConversationStart() that are listed here won't show up in the smart typing tool. But you can type them in directly.
You can remove "using Language.Lua".
Messages like OnConversationStart() that are listed here won't show up in the smart typing tool. But you can type them in directly.
Re: Beginner's question about dialogue Fields and C#
Sorry, it's me again.
When I copy your code in my class:
void OnConversationLine(Subtitle subtitle) // Called when the conversation gets to a dialogue entry.
{
string fieldValue = Field.LookupValue(subtitle.dialogueEntry, "abcdcustomfield");
Debug.Log("Current line's 'My Custom Field' value is: " + fieldValue);
}
It results of an error message from the string fieldValue declaration: "Conversion of 'PixelCrusher.DialogueSystem.DialogueEntry' in 'System.Collections.Generic.List<PixelCrushers.DialogueSystem.Field>'
They are apparently not from the same type...
That's the last time I bother you, promise!
When I copy your code in my class:
void OnConversationLine(Subtitle subtitle) // Called when the conversation gets to a dialogue entry.
{
string fieldValue = Field.LookupValue(subtitle.dialogueEntry, "abcdcustomfield");
Debug.Log("Current line's 'My Custom Field' value is: " + fieldValue);
}
It results of an error message from the string fieldValue declaration: "Conversion of 'PixelCrusher.DialogueSystem.DialogueEntry' in 'System.Collections.Generic.List<PixelCrushers.DialogueSystem.Field>'
They are apparently not from the same type...
That's the last time I bother you, promise!
Re: Beginner's question about dialogue Fields and C#
Oops, sorry, typo. I forgot to add ".fields":
Code: Select all
string fieldValue = Field.LookupValue(subtitle.dialogueEntry.fields, "My Custom Field");
Re: Beginner's question about dialogue Fields and C#
Thank you so much for your help!
I just got one more question (Yes, I know. I told you I wont).
How can I grab informations from Dialogues custom fields that are pointed my a response menu.
For example, if there are two choices avaiable, how can I get the "fields" field from these dialogue choices?
Still a beginner!
Have a grat day!
I just got one more question (Yes, I know. I told you I wont).
How can I grab informations from Dialogues custom fields that are pointed my a response menu.
For example, if there are two choices avaiable, how can I get the "fields" field from these dialogue choices?
Still a beginner!
Have a grat day!
Re: Beginner's question about dialogue Fields and C#
Hi Alain,
The OnConversationResponseMenu method provides the list of responses. (You can also get it from DialogueManager.currentConversationState.) Each response has a property that points to its destination dialogue entry.
The OnConversationResponseMenu method provides the list of responses. (You can also get it from DialogueManager.currentConversationState.) Each response has a property that points to its destination dialogue entry.
Code: Select all
void OnConversationResponseMenu(Response[] responses)
{
foreach (var response in responses)
{
string menuText = response.formattedText.text;
string customValue = Field.LookupValue(response.destinationEntry.fields, "My Custom Field);
Debug.Log("The custom field for '" + menuText + "' is: " + customValue);
}
}
Re: Beginner's question about dialogue Fields and C#
Aaaaaargh!
I tried to access it from DialogueManager.currentConversationState, but can't figure out how it works...
Asking you AGAIN....
I tried to access it from DialogueManager.currentConversationState, but can't figure out how it works...
Asking you AGAIN....
Re: Beginner's question about dialogue Fields and C#
Hi,
API reference: DialogueManager.currentConversationState
A conversation state contains:
Example code:
API reference: DialogueManager.currentConversationState
A conversation state contains:
- subtitle: The dialogue entry currently being shown. (Or most recently shown, if showing a response menu.)
- npcResponses: NPC nodes linked from the subtitle's dialogue entry whose conditions are true.
- pcResponses: Player nodes linked from the subtitle's dialogue entry whose conditions are true.
Example code:
Code: Select all
foreach (var response in DialogueManager.currentConversationState.pcResponses)
{
string menuText = response.formattedText.text;
string customValue = Field.LookupValue(response.destinationEntry.fields, "My Custom Field);
Debug.Log("The custom field for '" + menuText + "' is: " + customValue);
}