Page 1 of 1

Trying to use code to trigger a conversation

Posted: Mon Aug 29, 2022 8:40 am
by Aldurroth
I'm trying to write a C# scripts that can trigger a conversation based on an Int I created in the dialogue system.

So in my game the character has some chores to do. Each time he dose one the Variable associated with it ticks up by one in the Dialogue tab. Once this number reaches 18 I want to trigger a conversation.

So what i'm thinking is that I need a C# script that can keep track of the spastic Variable in the dialogue system, and when it reaches a threshold I then trigger the conversation in script. Then i'll destroy the triggering game object just to be safe.

The problem is that I don't know how to get access to my Variables in the dialogue tool.

Re: Trying to use code to trigger a conversation

Posted: Mon Aug 29, 2022 8:57 am
by Tony Li
Hi,

Use DialogueLua.GetVariable/SetVariable to access Dialogue System variables.

Use DialogueManager.StartConversation to start conversations.

Example:

Code: Select all

using PixelCrushers.DialogueSystem; // (Put at top of script)
...
int choresCompleted = DialogueLua.GetVariable("ChoresCompleted").asInt;
choresCompleted++;
DialogueLua.SetVariable("ChoresCompleted", choresCompleted);
if (choresCompleted == 18)
{
    DialogueManager.StartConversation("18 Chores Completed");
}

Re: Trying to use code to trigger a conversation

Posted: Mon Aug 29, 2022 9:17 am
by Aldurroth
Thank you. That did it!

Re: Trying to use code to trigger a conversation

Posted: Mon Aug 29, 2022 11:21 am
by Tony Li
Glad to help!