[Solved!] How to progress to the next line of a conversation via C# script

Announcements, support questions, and discussion for the Dialogue System.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

[Solved!] How to progress to the next line of a conversation via C# script

Post by CodePrincess »

Good afternoon everybody! Okay, I'm working on an extra-tricky component of my game, but I think I have... most of it figured out.

I need to add a Dialogue System Events script to the Dialogue Manager, then add a script to "OnConversationLineEnd()".
It will use PixelCrushers.DialogueSystem.DialogueLua.GetVariable() to check on one named "EVIDENCE", then activates the inventory if it's set to true.

Then, I add a script to a custom "confirm" button in the inventory that uses PixelCrushers.DialogueSystem.DialogueLua.SetVariable() to set a dialogue text variable called, say, "CHOSEN ITEM" to the selected Item's ID before closing the inventory menu.

Where I'm stuck now is how to advance to the next line once the inventory closes instead of tapping the continue button.

What would be the best solution to this problem?
Thank you so much for your help!
Last edited by CodePrincess on Sat Nov 16, 2019 2:06 pm, edited 3 times in total.
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to progress to the next line of a conversation via C# script

Post by Tony Li »

Hi!

Set the Sequence field to:

Code: Select all

Continue()@Message(InventoryClosed)
The Continue() command continues to the next line. The @Message part makes it wait until it receives a sequencer message "InventoryClosed".

When you close the inventory, send the sequencer message "InventoryClosed". Since you're using Inventory Engine, you can also hook into Inventory Engine's message system to know when the inventory has closed. You could add a script like this to the Inventory or the Dialogue Manager:

InventorySequencerMessages.cs

Code: Select all

using UnityEngine;
using MoreMountains.Tools;
using MoreMountains.InventoryEngine;
using PixelCrushers.DialogueSystem;

public class InventorySequencerMessages : MonoBehaviour, MMEventListener<MMInventoryEvent>
{
    public string inventoryToWatch = "MainInventory";

    private void OnEnable()
    {
        this.MMEventStartListening<MMInventoryEvent>(); // Listen for inventory events.
    }

    private void OnDisable()
    {
        this.MMEventStopListening<MMInventoryEvent>(); // Stop listening when disabled.
    }
    
    public void OnMMEvent(MMInventoryEvent inventoryEvent) // Handle Inventory Engine event messages.
    {
        if (inventoryEvent.TargetInventoryName == this.TargetInventoryName)
        {
            switch (inventoryEvent.InventoryEventType)
            {
                case MMInventoryEventType.InventoryCloses:
                    Sequencer.Message("InventoryClosed"); // Tell the DS sequencer that the inventory closed.
                    break;
            }
        }
    }
}
(There might be typos or bugs. I just typed it directly into this reply.)

One more note: If you're checking the value of the variable immediately after the inventory closes, add one node in between as described in Conversations Evaluate Conditions One Extra Level Ahead
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: How to progress to the next line of a conversation via C# script

Post by CodePrincess »

Alright, it's working! All I need is to have the inventory drawn on top of the Dialogue box and I'm done!


Raising Inventory sort order...
Dialogue Manager... at 0 already.
Uh-oh. :?
Um... how would you get the inventory to draw on top of the Dialogue box?
Thanks again!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to progress to the next line of a conversation via C# script

Post by Tony Li »

If you can't make the inventory canvas's sort order a higher priority (e.g., 1 or higher), you can lower the Dialogue Manager's sort order to -1.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: How to progress to the next line of a conversation via C# script

Post by CodePrincess »

Should I put them on the same layer?
Oh, wait. Is the inventory's personal camera an issue?
:shock: Does this count as a Dialogue System question?

Well, anyway, Good night, and thanks as always for everything! :D
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to progress to the next line of a conversation via C# script

Post by Tony Li »

I forgot Inventory Engine's example uses a Screen Space - Camera canvas. Screen Space - Overlay canvases are always drawn on top of Screen Space - Camera canvases.

You can either change Inventory Engine's canvas to Screen Space - Overlay, or change the Dialogue Manager's to Screen Space - Camera.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: [Solved!] How to progress to the next line of a conversation via C# script

Post by CodePrincess »

It works! :D Aww man, this is really starting to turn into the game I hoped it would be!

Thank you so much for your help. You're awesome!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: [Solved!] How to progress to the next line of a conversation via C# script

Post by Tony Li »

Always happy to help! Feel free to post screenshots of your game any time. I'm excited to see how it's turning out.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: [Solv...wait...] How to progress to the next line of a conversation via C# script

Post by CodePrincess »

Um, is this how to send sequencer messages?


Right now, it's just stuck waiting for the inventory to close.
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: [Solv...wait...] How to progress to the next line of a conversation via C# script

Post by Tony Li »

Hi,

To send the sequencer message InventoryClosed, use this:

Code: Select all

None()->Message(InventoryClosed)
This does nothing (the "None" part) and at the end sends the sequencer message InventoryClosed.

The SendMessage() sequencer command, in contrast, is similar to Unity's SendMessage() method in C#. It calls a script method on C# scripts on a GameObject.
Post Reply