Running several conversations in a script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
lostmushroom
Posts: 185
Joined: Mon Jul 01, 2019 1:21 pm

Running several conversations in a script

Post by lostmushroom »

Hey Tony, I'm setting up character scheduling for my game and the way I'd like to do it is by creating a method to run several conversations in my scheduling script.

These conversations have no dialogue in them, all they do is turn game objects on and off. This is what I've got right now.

Code: Select all

public void ScheduleCharacters()
    {
        DialogueManager.StopConversation();
        DialogueManager.StartConversation("ACT 1/Mayor/Calendar");
        
        DialogueManager.StopConversation();
        DialogueManager.StartConversation("ACT 1/Princess/Calendar");
        
        DialogueManager.StopConversation();
        DialogueManager.StartConversation("ACT 1/Grandfather/Calendar");

    }
But this is only working for the last character in the list, I guess because using the StopConversation(); is stopping it before it can run?

Basically I just want to run several conversations one after the other controlled by script. Do you know a better way to do this?

Thanks! (:
User avatar
Tony Li
Posts: 20755
Joined: Thu Jul 18, 2013 1:27 pm

Re: Running several conversations in a script

Post by Tony Li »

Hi,

Here are a few ways you could do that:

1. If each conversation has only one node linked from <START>, and that node has a sequence, you could run the sequence instead of the conversation:

Code: Select all

PlaySequenceInConversation("ACT 1/Mayor/Calendar");
PlaySequenceInConversation("ACT 1/Princess/Calendar");
PlaySequenceInConversation("ACT 1/Grandfather/Calendar");
...
void PlaySequenceInConversation(string conversationTitle)
{ // If the sequence uses 'speaker' or 'listener', you could pass those transforms to this method.
    var conversation = DialogueManager.masterDatabase.GetConversation(conversationTitle);
    var sequence = conversation.dialogueEntries[1].currentSequence;
    DialogueManager.PlaySequence(sequence); // Pass speaker/listener transforms here if necessary.
}

2. Or you could tick the Dialogue Manager's Other Settings > Allow Simultaneous Conversations and not stop the other conversations:

Code: Select all

DialogueManager.StartConversation("ACT 1/Mayor/Calendar");
DialogueManager.StartConversation("ACT 1/Princess/Calendar");
DialogueManager.StartConversation("ACT 1/Grandfather/Calendar");

3. Or you could set up a Dialogue System Trigger for each one and tick the Queue checkbox to queue them to run in sequence. Then call the Dialogue System Triggers' OnUse() methods.


4. Or you could queue it yourself:

Code: Select all

var conversationQueue = new Queue<string>(new string[] { "ACT 1/Mayor/Calendar", "ACT 1/Princess/Calendar", "ACT 1/Grandfather/Calendar" });
 DialogueManager.instance.conversationEnded += OnConversationEnded;
 PlayNextConversationInQueue();
 ...
 void OnConversationEnded(Transform actor) { PlayNextConversationInQueue(); }
 ...
 void PlayNextConversationInQueue()
 {
     if (conversationQueue.Count > 0)
     {
         DialogueManager.StartConversation(conversationQueue.Dequeue());
     }
 }
Post Reply