Hi,
maybe it was asked before?
How can i set or give a quest per code?
Set Quest per code
Re: Set Quest per code
Hi,
Use QuestMachine.SetQuestState(). (Or SetQuestNodeState(), GetQuestState(), GetQuestNodeState(), etc.)
Use QuestMachine.SetQuestState(). (Or SetQuestNodeState(), GetQuestState(), GetQuestNodeState(), etc.)
-
- Posts: 11
- Joined: Wed Nov 27, 2019 4:45 pm
Re: Set Quest per code
Hi Tony,
what`s the first param StringField? Is there any way to get all the quests from the project?
what`s the first param StringField? Is there any way to get all the quests from the project?
Re: Set Quest per code
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:
StringField example:
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.
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);
Code: Select all
QuestMachine.SetQuestState(new StringField("My Quest"), QuestState.Active);
If you want only the player's quests, use QuestMachine.GetQuestJournal().questList.
-
- Posts: 11
- Joined: Wed Nov 27, 2019 4:45 pm
Re: Set Quest per code
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?
For getting all quests is there a way to show them as dropdown in a custom script?
Re: Set Quest per code
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:
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);