Variable Scope
Variables in the Dialogue System are global. Some designers add "scope" by including it at the front of the variable name, such as:
- France.Population
- France.GDP
- France.Official_Language
- Spain.Population
- Spain.GDP
- Spain.Official_Language
In version 2.2.5+, variables with "." are shown as submenus in dropdowns:

Custom Fields
You can also add your own fields to a quest. In the example below, I added a field named "XP" to a quest. You can also add this field to the Quests template on the Templates tab so it gets added to all quests.

To get the value of this field in your own C# scripts:
Code: Select all
int XPReward = DialogueLua.GetQuestField("Get the Launch Codes", "XP").asInt;
Custom Field Types
You can also create your own custom field types. In the screenshot below, I created a new field type named "Mission Type". It has 3 choices: Main, Side, or Companion.

To create your own type, copy the template in Plugins/Pixel Crushers/Dialogue System/Templates/Scripts/Editor. There is also another example type in there, as well as another in Plugins/Pixel Crushers/Dialogue System/Scripts/Editor/Fields/Example.
The code for the Mission Type is here:
Code: Select all
using UnityEngine;
using UnityEditor;
using System;
namespace PixelCrushers.DialogueSystem
{
public enum MissionType
{
Main,
Side,
Companion
}
[CustomFieldTypeService.Name("Mission Type")]
public class QuestType : CustomFieldType
{
public override string Draw(string currentValue, DialogueDatabase dataBase)
{
var enumValue = GetCurrentMissionType(currentValue);
return EditorGUILayout.EnumPopup(enumValue).ToString();
}
public override string Draw(Rect rect, string currentValue, DialogueDatabase dataBase)
{
var enumValue = GetCurrentMissionType(currentValue);
return EditorGUI.EnumPopup(rect, enumValue).ToString();
}
private MissionType GetCurrentMissionType(string currentValue)
{
if (string.IsNullOrEmpty(currentValue)) currentValue = MissionType.Main.ToString();
try
{
return (MissionType)Enum.Parse(typeof(MissionType), currentValue, true);
}
catch (Exception)
{
return MissionType.Main;
}
}
}
}
Code: Select all
bool isSideMission = DialogueLua.GetQuestField("Get the Launch Codes", "Mission Type").asString;