How To: Create Quest In Code
Posted: Wed Jan 09, 2019 4:52 pm
Should anyone need to know how to add a quest to a database in code, here are the steps:
Quests share the dialogue database's Items table, which is why the Dialogue Editor tab is named "Quests/Items".
Use the Template class to create conversations, dialogue entries, etc. If you're writing an editor script, you can use TemplateTools to create an instance of the Template class that uses any custom fields you've defined in the Dialogue Editor's Template section. For example:
If it turns out that you need to use a template at runtime, in which case EditorPrefs isn't available, use Template.FromDefault:
To create a quest in 2.1.0 and earlier, use Template.CreateItem:
(Make sure you give it a unique ID number. The Dialogue Editor does this by finding the current highest ID and then adding 1.)
Then you'd need to add the fields that are specific to quests, such as:
However, if you import this patch: DS_TemplatePatch_2019-01-09.unitypackage
It exposes Template.CreateQuest:
This adds these fields for you:
Finally, if the Dialogue Editor window is open, reset it so it picks up the changed data:
Quests share the dialogue database's Items table, which is why the Dialogue Editor tab is named "Quests/Items".
Use the Template class to create conversations, dialogue entries, etc. If you're writing an editor script, you can use TemplateTools to create an instance of the Template class that uses any custom fields you've defined in the Dialogue Editor's Template section. For example:
Code: Select all
var template = TemplateTools.LoadFromEditorPrefs();
Code: Select all
var template = Template.FromDefault();
To create a quest in 2.1.0 and earlier, use Template.CreateItem:
Code: Select all
var quest = template.CreateItem(aUniqueID, "My Quest");
database.items.Add(quest);
Then you'd need to add the fields that are specific to quests, such as:
Code: Select all
quest.fields.Add(new Field("Success Description", "", FieldType.Text);
It exposes Template.CreateQuest:
Code: Select all
var quest = template.CreateQuest(aUniqueID, "My Quest");
- Description
- Success Description
- Failure Description
- State
- Entry Count
- Entry # State
- Entry #
Finally, if the Dialogue Editor window is open, reset it so it picks up the changed data:
Code: Select all
if (DialogueEditorWindow.instance != null) DialogueEditorWindow.instance.Reset();