Another Conversation is Triggered.

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 21079
Joined: Thu Jul 18, 2013 1:27 pm

Re: Another Conversation is Triggered.

Post by Tony Li »

This is a version of RememberCurrentDialogueEntry.cs from the Visual Novel Framework that I modified so it doesn't require the Visual Novel Framework. Add it to your Dialogue Manager:

Code: Select all

using UnityEngine;

namespace PixelCrushers.DialogueSystem
{

    /// <summary>
    /// Add this script to your Dialogue Manager if you want to keep track
    /// of the current conversation and dialogue entry. When you load a game,
    /// it will resume the conversation at that point.
    /// </summary>
    public class RememberCurrentDialogueEntry : MonoBehaviour
    {

        public void OnConversationStart(Transform actor)
        {
            var actorName = (DialogueManager.CurrentActor != null) ? DialogueManager.CurrentActor.name : string.Empty;
            var conversantName = (DialogueManager.CurrentConversant != null) ? DialogueManager.CurrentConversant.name : string.Empty;
            DialogueLua.SetVariable("CurrentConversationActor", actorName);
            DialogueLua.SetVariable("CurrentConversationConversant", conversantName);
            Debug.Log("<color=cyan>Starting conversation between " + actorName + " and " + conversantName + "</color>");
        }

        public void OnConversationLine(Subtitle subtitle)
        {
            DialogueLua.SetVariable("CurrentConversationID", subtitle.dialogueEntry.conversationID);
            DialogueLua.SetVariable("CurrentEntryID", subtitle.dialogueEntry.id);
            Debug.Log("<color=cyan>Recording current conversation position as conversation #" + subtitle.dialogueEntry.conversationID + " and entry #" + subtitle.dialogueEntry.id + "</color>");            
        }

        public void OnConversationEnd(Transform actor)
        {
            Debug.Log("<color=cyan>Recording that the conversation ended.</color>");
            DialogueLua.SetVariable("CurrentConversationID", -1);
        }

        public void OnApplyPersistentData()
        {
            if (!enabled) return;
            var conversationID = DialogueLua.GetVariable("CurrentConversationID").AsInt;
            var entryID = DialogueLua.GetVariable("CurrentEntryID").AsInt;
            Debug.Log("<color=cyan>Checking if we should resume conversation # " + conversationID + " entry #" + entryID + "</color>");
            if (conversationID >= 0 && entryID > 0)
            {
                var conversation = DialogueManager.MasterDatabase.GetConversation(conversationID);
                var actorName = DialogueLua.GetVariable("CurrentConversationActor").AsString;
                var conversantName = DialogueLua.GetVariable("CurrentConversationConversant").AsString;
                var actor = GameObject.Find(actorName);
                var conversant = GameObject.Find(conversantName);
                var actorTransform = (actor != null) ? actor.transform : null;
                var conversantTransform = (conversant != null) ? conversant.transform : null;
                Debug.Log("<color=cyan>Yes. Stopping old conversation (if any).</color>");
                DialogueManager.StopConversation();
                Debug.Log("<color=cyan>Resuming conversation '" + conversation.Title + "' between " + actorTransform + " and " + conversantTransform + "</color>");
                DialogueManager.StartConversation(conversation.Title, actorTransform, conversantTransform, entryID);
            }
        }
    }
}
HaiiroMukuro
Posts: 80
Joined: Sun Jul 17, 2016 3:38 pm

Re: Another Conversation is Triggered.

Post by HaiiroMukuro »

Is this correct?
Image
Still not working. Should I put the script insde the Menu script?
Oh, there's an error also.
Image
User avatar
Tony Li
Posts: 21079
Joined: Thu Jul 18, 2013 1:27 pm

Re: Another Conversation is Triggered.

Post by Tony Li »

That MissingReferenceException is probably fine, especially if it occurs when you stop the game. You probably have something that references a GameObject that gets destroyed when the game stops. If you'd like to investigate it, please click on that line in the Console window and press Ctrl+C to copy the full details to the clipboard. Then paste it in a reply or email it to tony (at) pixelcrushers.com, whichever you prefer.

Yes, you added the RememberCurrentDialogueEntry script to the correct place. I just edited the script in my previous reply. Please use the new version in my previous reply. It will add information to the Console window similar to this:

Starting conversation between actor and conversant.
Recording current conversation position as conversation #99 and entry #99.
Recording that the conversation ended.
Checking if we should resume conversation #99 and entry #99.
Yes. Stopping old conversation (if any).
Resuming conversation 'title' between actor and conversant.


These lines will be in cyan (light blue) to make them easy for you to find. They might help you identify the issue. If you don't see the lines, your game may be using a different Dialogue Manager GameObject that doesn't have the RememberCurrentDialogueEntry script.

You're also always welcome to send a copy of your project to tony (at) pixelcrushers.com. I'll be happy to take a look.
HaiiroMukuro
Posts: 80
Joined: Sun Jul 17, 2016 3:38 pm

Re: Another Conversation is Triggered.

Post by HaiiroMukuro »

It work, thanks! :D
Can it save also the states of sequencer? Like the SetActive()
Later I'll send the project. :D
User avatar
Tony Li
Posts: 21079
Joined: Thu Jul 18, 2013 1:27 pm

Re: Another Conversation is Triggered.

Post by Tony Li »

To state active/inactive state, use Persistent Active Data. You must put this on a GameObject that starts active in the scene.

When you activate a GameObject using SetActive(), also set a Dialogue System variable using SetVariable(). For example, say you have a GameObject named Lamp. Add a variable to your dialogue database named something like "Lamp_Is_On". Use this sequence to set the Lamp active:

Code: Select all

SetActive(Lamp);
SetVariable(Lamp_Is_On,true)
Then in your Persistent Active Data component:
  • Assign Lamp to the Target field.
  • Add a Condition > Lua Condition:

    Code: Select all

    Variable["Lamp_Is_On"] == true
Post Reply