Is there a way to register a event

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
xxhaissamxx
Posts: 3
Joined: Tue Mar 13, 2018 5:56 am

Is there a way to register a event

Post by xxhaissamxx »

I want to catch quests states.
If there a quest state changed from "unassigned" to "active" i want to keep tracking it from code,
There is
StringEvent PixelCrushers.DialogueSystem.DialogueSystemEvents.QuestEvents.onQuestStateChange = new StringEvent()
An object reference is required to access non-static member `PixelCrushers.DialogueSystem.DialogueSystemEvents.QuestEvents.onQuestStateChange'
so what's wrong .
Thanks
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Is there a way to register a event

Post by Tony Li »

Hi,

There are a few ways you can do this.

Dialogue System Events is a component. Add it to the Dialogue Manager GameObject. Then assign event handlers in the inspector.

Or add your own script to the Dialogue Manager, and add special methods such as OnQuestStateChange:

Code: Select all

void OnQuestStateChange(string questName) {
    Debug.Log("Quest " + questName + " changed to " + QuestLog.GetQuestState(questName));
}
Or use the override delegates in the static QuestLog class. For example, to hook into the method that changes a quest state:

Code: Select all

QuestLog.SetQuestStateOverride = CustomSetQuestState;

void CustomSetQuestState(string questName, string state) {
    // Log a message:
    Debug.Log("Setting quest " + questName + " to " + state);
    
    // Then use the default functionality:
    DefaultSetQuestState(questName, state);
}
zippo227
Posts: 8
Joined: Thu May 03, 2018 6:44 pm

Re: Is there a way to register a event

Post by zippo227 »

Just wanted to point that QuestLog.SetQuestStateOverride in Versions 1.7.7.1 and later of the Dialogue System. I was looking for it in 1.7.6 and could not find it.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Is there a way to register a event

Post by Tony Li »

Thanks for pointing that out. You probably already found it in the Release Notes, but I thought I'd post the link in case others in the future need to look up what version something was added in.
Post Reply