Page 1 of 1

Is there a way to register a event

Posted: Tue Mar 13, 2018 6:11 am
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

Re: Is there a way to register a event

Posted: Tue Mar 13, 2018 9:29 am
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);
}

Re: Is there a way to register a event

Posted: Sun May 13, 2018 3:24 pm
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.

Re: Is there a way to register a event

Posted: Sun May 13, 2018 8:53 pm
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.