Trying to use code to trigger a conversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

Trying to use code to trigger a conversation

Post 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.
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to use code to trigger a conversation

Post 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");
}
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

Re: Trying to use code to trigger a conversation

Post by Aldurroth »

Thank you. That did it!
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to use code to trigger a conversation

Post by Tony Li »

Glad to help!
Post Reply