Page 1 of 1

How To: Create Quest In Code

Posted: Wed Jan 09, 2019 4:52 pm
by Tony Li
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:

Code: Select all

var template = TemplateTools.LoadFromEditorPrefs();
If it turns out that you need to use a template at runtime, in which case EditorPrefs isn't available, use Template.FromDefault:

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);
(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:

Code: Select all

quest.fields.Add(new Field("Success Description", "", FieldType.Text);
However, if you import this patch: DS_TemplatePatch_2019-01-09.unitypackage

It exposes Template.CreateQuest:

Code: Select all

var quest = template.CreateQuest(aUniqueID, "My Quest");
This adds these fields for you:
  • Description
  • Success Description
  • Failure Description
  • State
If you plan to use quest entries (subtasks), you'll need to add these fields yourself:
  • Entry Count
  • Entry # State
  • Entry #
where # is the entry number, counting from 1.

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();