Tracking an active Quest from code?
Tracking an active Quest from code?
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
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
Re: Tracking an active Quest from code?
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:
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:
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");
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)
Re: Tracking an active Quest from code?
Excellent. Thanks Tony. It's really cool that we also have quest functionality in this tool.
Re: Tracking an active Quest from code?
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.
Re: Tracking an active Quest from code?
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?
- 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?
Re: Tracking an active Quest from code?
Hi,
Every quest has two tracking-related Boolean fields:
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():
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:
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.
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();
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();
Re: Tracking an active Quest from code?
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
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
Re: Tracking an active Quest from code?
Hi Jeff,
only sets the value of the variable "State" that's in the array element Quest["Find_something_to_kindle_fire"].
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: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"
Code: Select all
SetQuestState("Find something to kindle fire", "active")
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.
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 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?
Re: Tracking an active Quest from code?
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!
Re: Tracking an active Quest from code?
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.