Page 1 of 1

Top Down Engine item best practices.

Posted: Sun Jun 04, 2023 3:38 pm
by MIKEeRTY
As the title suggests, I'm using Top Down Engine and Dialogue System to make my game.
I had just gotten the hang of TDE and it's inventory/item system when I introduced DS to handle dialogue.
I'm finding it very difficult to work out the correct or best way to communicate to BOTH assets that an item has been obtained.

For example: I have a special coin which is obtained. There is only one.
There is a Dialogue System quest entry named "Special Coin Obtained" (bool).
The Top Down Engine picks up the coin and adds an entity to the inventory which can be inspected which is something I really want to keep.
But how do I send a message to the dialogue database to say "Special Coin Obtained = true" from the Top Down Engine Item Picker/OnUse/Any script that deals with item gathering? The closest I thought I came was sending a message with events... but I had no idea what message to send, and to where :?

I apologise if this is very easy but I'm just having diffuiculty reconciling the two systems. I love them both and feel like I just have to work out a couple of these kinks and I'll be up and running.

Re: Top Down Engine item best practices.

Posted: Sun Jun 04, 2023 7:12 pm
by Tony Li
Hi,

Add a Dialogue System Inventory Event Listener component to your Inventory GameObject (typically the main inventory). Then set up the OnContentChanged() UnityEvent. If you don't mind some scripting, you can do something like:

Code: Select all

[QuestPopup(true)] public string quest; // Assign in inspector.
[QuestEntryPopup] public int questEntry;

void OnEnable()
{
    GetComponent<DialogueSystemInventoryEventListener>().onContentChanged.AddListener(OnContentChanged);
}

void OnDisable()
{
    GetComponent<DialogueSystemInventoryEventListener>().onContentChanged.RemoveListener(OnContentChanged);
}

void OnContentChanged()
{
    if (GetComponent<Inventory>().GetQuantity("Coin") >= 1)
    {
        QuestLog.SetQuestEntryState(quest, questEntry, QuestState.Success);
        DialogueManager.SendUpdateTracker();
    }
}
Or you can set it up in the inspector instead:

inventoryEngineListener.png
inventoryEngineListener.png (52.71 KiB) Viewed 412 times

You could also add another Dialogue System Trigger that checks if the player dropped the coin. If so, set the quest entry back to its previous state.