Page 1 of 2

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

Posted: Wed Nov 13, 2019 4:35 pm
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!

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

Posted: Wed Nov 13, 2019 6:07 pm
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

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

Posted: Wed Nov 13, 2019 10:03 pm
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!

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

Posted: Wed Nov 13, 2019 10:16 pm
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.

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

Posted: Wed Nov 13, 2019 10:37 pm
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

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

Posted: Thu Nov 14, 2019 7:50 am
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.

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

Posted: Thu Nov 14, 2019 9:31 am
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!

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

Posted: Thu Nov 14, 2019 9:32 am
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.

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

Posted: Fri Nov 15, 2019 11:19 pm
by CodePrincess
Um, is this how to send sequencer messages?


Right now, it's just stuck waiting for the inventory to close.

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

Posted: Sat Nov 16, 2019 7:12 am
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.