Question about extending quests
-
- Posts: 97
- Joined: Thu Aug 12, 2021 6:39 pm
Question about extending quests
Hello, I am seeking some advice. I already have a bunch of tutorial quests in the dialogue system and they are working. I would like to make a bulletin board where the player gets random quests. I know quest machine can do this but I can code some random quests myself and I already have some quests in the dialogue system so I don't really want to switch and import another asset just for this. The only difference is these quests would be generated at runtime and they would expire after a certain amount of time. I was thinking I could just extend the Quest class (but I can't find it for some reason). And I'm not sure they would show up in the Quest log UI since they are generated at run time. Do I need to make my own system to handle these quests? If so, I guess that would mean I'd have to modify the Quest log UI and Quest HUD?
Re: Question about extending quests
Hi,
Runtime quest data is still stored in the Dialogue System's memory (i.e., Lua environment). To create a quest at runtime, use the QuestLog class. Example:
You can make a runtime conversation, too. See: How To: Create a Dialogue Database at Runtime
Runtime quest data is still stored in the Dialogue System's memory (i.e., Lua environment). To create a quest at runtime, use the QuestLog class. Example:
Code: Select all
QuestLog.AddQuest("Bake a Pie", "The village baker wants to teach me to bake a pie.");
QuestLog.AddQuestEntry("Bake a Pie", "Slice Apples");
QuestLog.AddQuestEntry("Bake a Pie", "Roll Crust");
QuestLog.AddQuestEntry("Bake a Pie", "Put Pie in Oven");
QuestLog.SetQuestTrackingAvailable("Bake a Pie", true); // Trackable checkbox
QuestLog.SetQuestTracking("Bake a Pie", true); // Track On Start checkbox
-
- Posts: 97
- Joined: Thu Aug 12, 2021 6:39 pm
Re: Question about extending quests
Thanks, I am trying it out just have a couple follow up questions:
It looks like if I make a new quest at runtime like you showed it will be stored in the default database? When I create a new database at runtime, I can see that I have access to actors, conversations etc, but not quests. In any case, I don't think I need to create a new database - I just need to add some quests at runtime and if possible add some extra parameters to these quests, however it doesn't look like I have access to the quest objects themselves in order to do that.
In the link you gave there is this method to add fields to a database entry:
Field.SetValue(actor.fields, "Title", "Gunnery Sergeant");
But I don't know how to get a reference to the quest object in order to do that. It looks like I can call QuestLog.GetAllQuests but that only returns an array of strings. Am I missing something?
It looks like if I make a new quest at runtime like you showed it will be stored in the default database? When I create a new database at runtime, I can see that I have access to actors, conversations etc, but not quests. In any case, I don't think I need to create a new database - I just need to add some quests at runtime and if possible add some extra parameters to these quests, however it doesn't look like I have access to the quest objects themselves in order to do that.
In the link you gave there is this method to add fields to a database entry:
Field.SetValue(actor.fields, "Title", "Gunnery Sergeant");
But I don't know how to get a reference to the quest object in order to do that. It looks like I can call QuestLog.GetAllQuests but that only returns an array of strings. Am I missing something?
Re: Question about extending quests
Hi,
You don't need to add quests to the dialogue database. When the Dialogue System starts up at runtime, it populates the Lua environment with the quests that are in the Dialogue Manager's Initial Database. The quests are then managed entirely in Lua, in a table (array) named Quest[].
The quest log window and quest HUD don't show the contents of the dialogue database. They show the contents of the Quest[] table.
When you use QuestLog.AddQuest(), it adds a new quest record to the Quest[] table. In addition to using QuestLog, you can also manually add fields to a quest's Lua record by using DialogueLua.SetQuestField(), such as:
BTW, QuestLog.GetAllQuests() returns a list of all of the quest names in the Quest[] table. You can provide a mask, such as:
or, without a mask, it returns the names of all currently-active quests:
You don't need to add quests to the dialogue database. When the Dialogue System starts up at runtime, it populates the Lua environment with the quests that are in the Dialogue Manager's Initial Database. The quests are then managed entirely in Lua, in a table (array) named Quest[].
The quest log window and quest HUD don't show the contents of the dialogue database. They show the contents of the Quest[] table.
When you use QuestLog.AddQuest(), it adds a new quest record to the Quest[] table. In addition to using QuestLog, you can also manually add fields to a quest's Lua record by using DialogueLua.SetQuestField(), such as:
Code: Select all
DialogueLua.SetQuestField("Bake a Pie", "XP Reward", 50);
Code: Select all
string[] allCompletedQuestNames = QuestLog.GetAllQuests(QuestState.Success | QuestState.Failure);
Code: Select all
string[] allActiveQuests = QuestLog.GetAllQuests();
-
- Posts: 97
- Joined: Thu Aug 12, 2021 6:39 pm
Re: Question about extending quests
Thank you. I think I understand enough to get started. I'm just having an issue that I need to debug more tomorrow. For some reason when I do a QuestLog.GetAllQuests() even with all the flags passed in as a mask it does not return my run-time created quests. I can see the quests are being created in the console so they should be there. I'll have to look into it more tomorrow.
Re: Question about extending quests
If you set the runtime-created quest's state to active, does it appear in the quest log window?
-
- Posts: 97
- Joined: Thu Aug 12, 2021 6:39 pm
Re: Question about extending quests
No, setting it to active doesn't change anything.
Here's the code I'm using to create the quest at runtime:
Here's what I see in the unity console at runtime:
But afterwards when I open the quest log or try to call QuestLog.GetAllQuests it doesn't show up. Other quests that are defined in the quest tab do show up normally.
Here's the code I'm using to create the quest at runtime:
Code: Select all
QuestLog.AddQuest("Nate Fetch Quest", "Nate wants 3 wood.", QuestState.Active);
QuestLog.AddQuestEntry("Bring Nate 3 wood", "Nate wants 3 wood.");
QuestLog.SetQuestTrackingAvailable("Bring Nate 3 wood", true); // Trackable checkbox
QuestLog.SetQuestTracking("Bring Nate 3 wood", true); // Track On Start checkbox
Code: Select all
Dialogue System: Lua(Item["Nate_Fetch_Quest"] = { Name = "Nate Fetch Quest", Is_Item = false, Description = "Nate wants 3 wood.", State = "active" })
Re: Question about extending quests
The first parameter should be the quest title. Try this:
or, better yet to prevent typos:
Code: Select all
QuestLog.AddQuest("Nate Fetch Quest", "Nate wants 3 wood.", QuestState.Active);
QuestLog.AddQuestEntry("Nate Fetch Quest", "Bring Nate 3 wood");
QuestLog.SetQuestTrackingAvailable("Nate Fetch Quest", true); // Trackable checkbox
QuestLog.SetQuestTracking("Nate Fetch Quest", true); // Track On Start checkbox
Code: Select all
string questTitle = "Nate Fetch Quest";
QuestLog.AddQuest(questTitle, "Nate wants 3 wood.", QuestState.Active);
QuestLog.AddQuestEntry(questTitle, "Bring Nate 3 wood");
QuestLog.SetQuestTrackingAvailable(questTitle, true); // Trackable checkbox
QuestLog.SetQuestTracking(questTitle, true); // Track On Start checkbox
-
- Posts: 97
- Joined: Thu Aug 12, 2021 6:39 pm
Re: Question about extending quests
Oh woops, thank you. That wasn't the issue but I was able to figure it out - I was testing using a save file which loads the dialogue database from a saved string (overwriting the quests I was creating on start up). So it all makes sense now =). Thank you.
Re: Question about extending quests
Glad to help!