Page 1 of 1

How to interrupt conversation and return conversation after interruption.

Posted: Fri Nov 17, 2023 11:23 am
by elda27
I tried following code so that I want to interrupt conversation and return conversation after interruption.
But there is not working.
Can I interrupt conversation?
And how can I start original conversation that is keeping node position after interruption?

Code: Select all

void Interrupt(string name)
{
        if (DialogueManager.IsConversationActive)
        {
            ConversationPositionStack.PushConversationPosition();
        }
        DialogueManager.StartConverastion(name)
}

// Callback function attached ConversationEvent
public void OnConversationEnd()
{
    try
    {
        ConversationPositionStack.PopConversationPosition();
    }
    catch
    {
        conversationStarted = false;
    }
}

Re: How to interrupt conversation and return conversation after interruption.

Posted: Fri Nov 17, 2023 11:50 am
by Tony Li
Hi,

To interrupt the conversation:

Code: Select all

string savedConversationTitle;
int savedEntryID;
Transform savedActor;
Transform savedConversant;

savedConversationTitle = DialogueManager.lastConversationStarted;
savedEntryID = DialogueManager.currentConversationState.subtitle.dialogueEntry.id;
savedActor = dialogueManager.currentActor;
savedConversant = DialogueManager.currentConversant;
DialogueManager.StopConversation();

// Then start a new conversation:
DialogueManager.StartConversation(...)
To resume the saved conversation:

Code: Select all

DialogueManager.StartConversation(savedConversationTitle, savedActor, savedConversant, savedEntryID);
However, if you want to temporarily dip into another conversation and then pop back to the previous conversation as if it's part of the same conversation, you can use the conversation position stack:

Code: Select all

ConversationPositionStack.PushConversationPosition();
var newEntry = DialogueManager.masterDatabase.GetConversation(name).GetFirstDialogueEntry();
var newState = DialogueManager.conversationModel.GetState(newEntry);
DialogueManager.conversationView.GotoState(newState);
The end of that conversation can call PopConversationPosition() in the Script field, or you can call it in C#. Make sure you've added a ConversationPositionStack component to your Dialogue Manager.

Re: How to interrupt conversation and return conversation after interruption.

Posted: Fri Nov 17, 2023 1:04 pm
by elda27
Thanks!

I tried your solution but I can't return previous conversation.
I seem that I use interrupt function at script field of a response panel probably.
I need to continue the next node of response panel.

There are nodes of conversations.
Node "B" is registered a script that Invokes Interrupt function after clicked the response panel.
Now, my code works interrupting another conversation after clicked "B".
But node "E" is not shown after finished another conversation.

A
├── B
│ └── E
├── C
└── D

Does your solution work in my situation?

Re: How to interrupt conversation and return conversation after interruption.

Posted: Fri Nov 17, 2023 2:28 pm
by Tony Li
If B is a player response node, you may want to record the next node instead of the current node:

Code: Select all

savedEntryID = DialogueManager.currentConversationState.subtitle.speakerInfo.isNPC
    ? DialogueManager.currentConversationState.subtitle.dialogueEntry.id
    : DialogueManager.currentConversationState.firstNPCResponse.destinationEntry.id;

Re: How to interrupt conversation and return conversation after interruption.

Posted: Sat Nov 18, 2023 8:24 am
by elda27
There is a node connection with its corresponding ID.

A (2)
├── B (3)
│ └── E (6)
├── C (4)
└── D (5)

Node B has Intterupt function in its script field (I was registered the Interrupt function from C# script).
If I clicked node B, I expected a scene displaying another conversation and node E after that.
But the scene displayed another conversation and node A in actual.
I understand saveEntryID should be six in my case.
But it is two in actual.

Code: Select all

savedEntryID = DialogueManager.currentConversationState.subtitle.speakerInfo.isNPC
    ? DialogueManager.currentConversationState.subtitle.dialogueEntry.id
    : DialogueManager.currentConversationState.firstNPCResponse.destinationEntry.id;
I attached image created conversation.
https://www.dropbox.com/scl/fi/xx080b0j ... l7pv0&dl=0

Re: How to interrupt conversation and return conversation after interruption.

Posted: Sat Nov 18, 2023 8:55 am
by Tony Li
Hi,

Should the conversation always go from B to the other conversation and then back? If so, you can use cross-conversation links:

conversation1.png
conversation1.png (26.52 KiB) Viewed 570 times
conversation2.png
conversation2.png (17.34 KiB) Viewed 570 times

This way you don't need any scripts or special code.

Re: How to interrupt conversation and return conversation after interruption.

Posted: Sat Nov 18, 2023 9:19 am
by elda27
Yes!
Can I confirm the background in my situation?

I think your method cannot continue previous conversation after end of another conversation.
If it goes back previous conversation, I need set link another conversation at end of another conversation.

I cannot set link to fixed conversation at another conversation because another conversation is common conversation in my game.
It means another conversation is linked multiple conversations.

I want to make like this.

Code: Select all

Conversation1 -> Conversation0 -> Conversation 1 (Continue where before interruption)
Conversation2 -> Conversation0 -> Conversation 2 (Continue where before interruption)
Can it be possible to solve without script in my situation?

Re: How to interrupt conversation and return conversation after interruption.

Posted: Sat Nov 18, 2023 3:00 pm
by Tony Li
Yes, you can use the Conversation Position Stack.

Here's an example:

DS_ConversationPositionStack_Interrupt_Example_2023-11-18.unitypackage

I added a Conversation Position Stack component to the Dialogue Manager.

In the dialogue database, I added a variable:

stack1.png
stack1.png (16.1 KiB) Viewed 561 times

Conversation 1 and Conversation 2 are set up like this:

stack2.png
stack2.png (35.13 KiB) Viewed 561 times

The "<Maybe Conversation 0>" node stores the current conversation position on the stack by calling PushConversationPosition(). When the player clicks the "B" node, it checks the variable value to decide whether to interrupt the conversation or continue to "E".


Conversation 0 is set up like this:

stack3.png
stack3.png (24.98 KiB) Viewed 561 times

It has an initial condition that requires the variable to be false. Then it sets the variable true.

The final node returns to the saved position by calling PopConversationPosition().

Re: How to interrupt conversation and return conversation after interruption.

Posted: Sun Nov 19, 2023 6:45 am
by elda27
Thank you very much!
I solved the problem!

Re: How to interrupt conversation and return conversation after interruption.

Posted: Sun Nov 19, 2023 8:38 am
by Tony Li
Glad to help!