get the length of the DialogueEntrys in a conversation?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

get the length of the DialogueEntrys in a conversation?

Post 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 :D
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Re: get the length of the DialogueEntrys in a conversation?

Post 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 :)
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: get the length of the DialogueEntrys in a conversation?

Post 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.
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Re: get the length of the DialogueEntrys in a conversation?

Post 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?
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: get the length of the DialogueEntrys in a conversation?

Post 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);
}
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Re: get the length of the DialogueEntrys in a conversation?

Post 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?
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: get the length of the DialogueEntrys in a conversation?

Post 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.
Post Reply