Tracking an active Quest from code?

Announcements, support questions, and discussion for the Dialogue System.
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Tracking an active Quest from code?

Post by Hyrad »

Last one for this week!

I would like to use the Quest tracker component on the Canvas inside the DialogueManager as standalone and tell it to start tracking an active quest through code? Any quick and dirty way to do this?

Thanks a bunch again,
-Jeff
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Tracking an active Quest from code?

Post by Tony Li »

Hi Jeff,

Call DialogueManager.SendUpdateTracker().

This happens automatically if you activate the quest using the QuestLog class or the SetQuestState() Lua function used in dialogue entry nodes' Script fields. So normally this will suffice:

Code: Select all

//Start quest (and automatically update tracker):
QuestLog.StartQuest("My Super Quest");
However, I overlooked something in the QuestLog class. If the quest is already active and you're simply toggling tracking from code using the QuestLog.SetQuestTracking() method, it doesn't automatically call DialogueManager.SendUpdateTracker(). I fixed it in the next release. In the meantime, you'll have to do this:

Code: Select all

QuestLog.SetQuestTracking("My Super Quest", true);
DialogueManager.SendUpdateTracker(); //(doh, sorry, prior to version 1.6.8 you must manually tell tracker to update)    
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Re: Tracking an active Quest from code?

Post by Hyrad »

Excellent. Thanks Tony. It's really cool that we also have quest functionality in this tool.
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Tracking an active Quest from code?

Post by Tony Li »

Thanks! I think so, too. When we designed the Dialogue System, we realized how interwoven conversations and quests are. For a AAA dialogue system, it was practically mandatory to smoothly integrate quest management.
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Re: Tracking an active Quest from code?

Post by Hyrad »

Hmmm, this is strange though, I can't get it to work. But if I set the Quest as trackable with track on start set to true, it appears right away in the Quest tracked HUD. What I did:

- Create a custom LUA function, UpdateDialogueManager() that sends calls the static mehtod: DialogueManager.SendUpdateTracker();
- From the convestation node that sets the Quest to active I call it from the script field. No errors reported, but the HUD doesn't update. Here's the code in the script (ChangeDialog is another custom LUA function I created):

Quest["Find_something_to_kindle_fire"].State == "active"; ChangeDialog("Eva_waiting_for_fire", "Nurse"); Variable["Alert"] = "I should go look for something to kindle a fire with..."; UpdateDialogueManager();


Here is the code for the custom function:

public void UpdateDialogueManager()
{
QuestLog.SetQuestTracking("Find_something_to_kindle_fire", true);
DialogueManager.SendUpdateTracker();
}

Any ideas?
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Tracking an active Quest from code?

Post by Tony Li »

Hi,

Every quest has two tracking-related Boolean fields:
  • Trackable: If true, quest is allowed to be tracked in the quest tracker HUD.
  • Track: If true (and if Trackable is true), actually show this quest in the quest tracker HUD.
The Trackable field also tells the quest log window whether to show a track on/off toggle for the quest. This toggle controls the value of Track.

Does your quest have a Trackable field that's set to true? In the Dialogue Editor, as you've seen, tick Trackable. In code, call QuestLog.SetQuestTrackingAvailable() at least once some time before using QuestLog.SetQuestTracking():

Code: Select all

QuestLog.SetQuestTrackingAvailable("Find something to kindle fire", true); // Allow it to be tracked...
QuestLog.SetQuestTracking("Find something to kindle fire", true); //...and actually track it.
DialogueManager.SendUpdateTracker();
Also, you can simplify your Lua code a bit if you want. The Dialogue System provides some functions to make it look a little nicer:

Code: Select all

SetQuestState("Find something to kindle fire", "active");
ChangeDialog("Eva_waiting_for_fire", "Nurse"); 
ShowAlert("I should go look for something to kindle a fire with...");
UpdateDialogueManager();
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Re: Tracking an active Quest from code?

Post by Hyrad »

Hi Tony, SetQuestState did the trick. Just wondering though about Quest["Find_something_to_kindle_fire"].State == "active" which I was using before; wasn't it doing exactly the same thing? Just wondering if they are redundant functions or if they have different uses cases.

Oh and just one quick question: since DialogueManager.SendUpdateTracker(); is a static function and it doesn't take any arguments, I conclude that if I would have more than one Dialog manager instance (each with their own Quest Tracker), the update would be sent to them all? Am I correct in assuming this?

Thanks as always!
-Jeff
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Tracking an active Quest from code?

Post by Tony Li »

Hi Jeff,
Hyrad wrote:Hi Tony, SetQuestState did the trick. Just wondering though about Quest["Find_something_to_kindle_fire"].State == "active" which I was using before; wasn't it doing exactly the same thing? Just wondering if they are redundant functions or if they have different uses cases.

Code: Select all

Quest["Find_something_to_kindle_fire"].State == "active"
only sets the value of the variable "State" that's in the array element Quest["Find_something_to_kindle_fire"].

Code: Select all

SetQuestState("Find something to kindle fire", "active")
on the other hand sets the variable and calls DialogueManager.SendUpdateTracker().

The original project that the Dialogue System came out of didn't use a quest tracker, so the first technique above was sufficient. When quest trackers were added to the Dialogue System, I added the SetQuestState() function.
Hyrad wrote:Oh and just one quick question: since DialogueManager.SendUpdateTracker(); is a static function and it doesn't take any arguments, I conclude that if I would have more than one Dialog manager instance (each with their own Quest Tracker), the update would be sent to them all? Am I correct in assuming this?
No, I'm afraid it only gets sent to the Dialogue Manager that's recorded as the current instance -- that is, the one assigned to the static property DialogueManager.Instance. Do you have a need for multiple Dialogue Managers?
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Re: Tracking an active Quest from code?

Post by Hyrad »

Not sure yet :) I was under the impression that this was the way to go if you had multiple Databases to work with, but I realize that this can be changed by switching it through code. Thanks for the explanations!
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Tracking an active Quest from code?

Post by Tony Li »

If you have multiple databases, it's best to use the same Dialogue Manager so they all share the same Lua environment, and add databases using DialogueManager.AddDatabase() or the Extra Databases component. For more info, see How to Use Multiple Databases.
Post Reply