Page 1 of 1
get the length of the DialogueEntrys in a conversation?
Posted: Wed Oct 19, 2016 4:27 am
by alfonso
Hi tony
it is possible to access to the total num of DialogueEntry of the current conversation? i have a custom action where i pass the current subtitle and the current DialogueUI. Of course can access to the DialogueManager singleton too, but dont know where i can access to this information.
thanks

Re: get the length of the DialogueEntrys in a conversation?
Posted: Wed Oct 19, 2016 8:23 am
by alfonso
Hi tony i think i get it.
it is correct to access with
"DialogueManager.MasterDatabase.GetConversation (subtitle.dialogueEntry.conversationID).dialogueEntries.Count - 1;"
or exist a better way?
thanks

Re: get the length of the DialogueEntrys in a conversation?
Posted: Wed Oct 19, 2016 9:11 am
by Tony Li
That will work. The total number of entries is "dialogueEntries.Count", not "dialogueEntries.Count - 1". Also keep in mind that each entry has an ID number. The ID doesn't have to correspond to the index of the dialogue entry in the dialogueEntries list.
So if you have 3 dialogue entries, they will be in dialogueEntries[0], dialogueEntries[1], and dialogueEntries[2]. But dialogueEntries[0].id won't necessarily be 0. It may be a different value.
Re: get the length of the DialogueEntrys in a conversation?
Posted: Thu Oct 20, 2016 6:20 am
by alfonso
wow that was a good point, so a better way to know the last id of the conversation will be :
Code: Select all
Conversation currentConversation = DialogueManager.MasterDatabase.GetConversation(subtitle.dialogueEntry.conversationID);
if(currentConversation != null)
{
int lastIndex = currentConversation.dialogueEntries.Count-1;
if(endID == currentConversation.dialogueEntries[lastIndex].id)
//exit
}
right?
Re: get the length of the DialogueEntrys in a conversation?
Posted: Thu Oct 20, 2016 9:28 am
by Tony Li
IDs aren't guaranteed to be in order. The only surefire way is like this:
Code: Select all
var endID = 0;
var currentConversation = DialogueManager.MasterDatabase.GetConversation(subtitle.dialogueEntry.conversationID);
currentConversation.dialogueEntries.ForEach(entry => endID = Mathf.Max(endID, entry.id));
I used List<T>.ForEach(), but the same idea applies if you use a traditional for/foreach loop. (List<T>.ForEach isn't available on the WinRT platform.) BTW, Monodevelop's compiler generates garbage (boxing) in some foreach loops, so I usually use for:
Code: Select all
for (int i = 0; i < currentConversation.dialogueEntries.Count; i++)
{
var entry = currentConversation.dialogueEntries[i];
endID = Mathf.Max(endID, entry.id);
}
Re: get the length of the DialogueEntrys in a conversation?
Posted: Thu Oct 20, 2016 10:00 am
by alfonso
but the maxID doesnt guarante that is the last one, i can have for example 4 nodes with ids (0,1,2,3) and the id 3 can be the first one, what i need is to check if the current node is the last one that will be showed and after that the dialague will be closed.
so maybe checking that doesnt have any link to another node will be a good clue to know that this is the last one?
Re: get the length of the DialogueEntrys in a conversation?
Posted: Thu Oct 20, 2016 10:18 am
by Tony Li
Ah, I understand. This may also depend on the current Conditions, so you can't just use the dialogue database. For example:
- Entry 0
- Dialogue Text: "See you later."
- Entry 1
- Dialogue Text: "Wait wait! I forgot to mention one more thing!."
- Conditions: Variable["OneMoreThing"] == true
If the variable "OneMoreThing" is true, then entry 0 is not the last entry. If "OneMoreThing" is false, then entry 0 is the last entry.
The best way to determine if the current node is the last one is to check the bool property
DialogueManager.CurrentConversationState.
HasAnyResponses.