Set Quest per code

Announcements, support questions, and discussion for Quest Machine.
Post Reply
BillyForce
Posts: 11
Joined: Wed Nov 27, 2019 4:45 pm

Set Quest per code

Post by BillyForce »

Hi,
maybe it was asked before?
How can i set or give a quest per code?
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Quest per code

Post by Tony Li »

Hi,

Use QuestMachine.SetQuestState(). (Or SetQuestNodeState(), GetQuestState(), GetQuestNodeState(), etc.)
BillyForce
Posts: 11
Joined: Wed Nov 27, 2019 4:45 pm

Re: Set Quest per code

Post by BillyForce »

Hi Tony,
what`s the first param StringField? Is there any way to get all the quests from the project?
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Quest per code

Post by Tony Li »

Hi,

There are two variants of QuestMachine.SetQuestState(). One takes a string, the other takes a StringField.

A StringField is a wrapper for a string, a StringAsset, or an entry in a Text Table.

String example:

Code: Select all

QuestMachine.SetQuestState("My Quest", QuestState.Active);
StringField example:

Code: Select all

QuestMachine.SetQuestState(new StringField("My Quest"), QuestState.Active);
If you want to get all the quests in the project, use QuestMachine.GetAllQuestInstances(). This returns a dictionary where the keys are quest IDs and the values are a list of instances of that quest ID. For example, if the player has picked up a quest from an NPC, the list will contain the player's instance of the quest and the NPC's original instance of the quest.

If you want only the player's quests, use QuestMachine.GetQuestJournal().questList.
BillyForce
Posts: 11
Joined: Wed Nov 27, 2019 4:45 pm

Re: Set Quest per code

Post by BillyForce »

Thats a really great description! Thank you so much!
For getting all quests is there a way to show them as dropdown in a custom script?
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Quest per code

Post by Tony Li »

Custom editor script or custom runtime script?

For a runtime script, I'll assume you're using a Unity UI Dropdown and you want to show the player's quests. Use something like this:

Code: Select all

List<string> options = new List<string>();
QuestMachine.GetQuestJournal().questList.ForEach(quest => options.Add(quest.id.value));
myDropdown.ClearOptions();
myDropdown.AddOptions(options);
Post Reply