Page 1 of 1

Set Quest per code

Posted: Sun Apr 19, 2020 9:09 am
by BillyForce
Hi,
maybe it was asked before?
How can i set or give a quest per code?

Re: Set Quest per code

Posted: Sun Apr 19, 2020 10:36 am
by Tony Li
Hi,

Use QuestMachine.SetQuestState(). (Or SetQuestNodeState(), GetQuestState(), GetQuestNodeState(), etc.)

Re: Set Quest per code

Posted: Sun Apr 19, 2020 10:53 am
by BillyForce
Hi Tony,
what`s the first param StringField? Is there any way to get all the quests from the project?

Re: Set Quest per code

Posted: Sun Apr 19, 2020 11:05 am
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.

Re: Set Quest per code

Posted: Sun Apr 19, 2020 11:53 am
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?

Re: Set Quest per code

Posted: Sun Apr 19, 2020 1:06 pm
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);