FindValue for enum Fields

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

FindValue for enum Fields

Post by Mackerel_Sky »

Hi Tony,

Finally have some time to look at fixing some minor bugs with the save system's integration into my project. In particular, I'm looking to fix the active quest not displaying properly in my save metadata info.

I don't have the code in front of me right now but the basic gist of it is that I'm trying to check first the group field of the quest (this works as a simple GetFieldValue method) and then check the state is active(this is the part I'm having issues with). There's only one active quest a time in the group.

Is there a GetField equivalent to the enum field used by the quest state? If I can use something similar or a different method to get the state it should be an easy fix. Or perhaps I'm looking at this the wrong way.

Let me know if this sounds doable to you - I'll try to get my hands on the relevant code tomorrow if it'll help.

Thanks!
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: FindValue for enum Fields

Post by Tony Li »

Hi,

When saving a game and pulling info into your metadata object, you can use the QuestLog class.

Methods that might be useful to you are:
  • QuestLog.GetQuestState("quest")
  • QuestLog.GetQuestGroup("quest")
  • QuestLog.GetAllQuests(), GetAllGroups(), and GetAllQuestsAndGroups()
  • QuestLog.StateToString() and StringToState()
Quest states and quest entry states are stored as strings in text fields. A quest's state is in the "State" field, and entry states are in "Entry # State" fields. So if you want to bypass the QuestLog class, you can always use DialogueLua.GetQuestField() or even Lua.Run().
Tip for pulling info not in metadata
Tip: If the info isn't in your metadata info and you need to pull it straight from the Dialogue System's saved data in an existing saved game, you can read the saved data, temporarily fill the Dialogue System's Lua environment with the Dialogue System data, and then use QuestLog, or use Lua.Run() to read it directly.

Example:

Code: Select all

SavedGameData savedGameData = SaveSystem.storer.RetrieveSavedGameData(slotNumber);
var dsData = savedGameData.GetData("DS key"); // Assumes Dialogue System Saver's key is "DS Key".
PersistentDataManager.ApplySaveData(dsData);
foreach (string quest in QuestLog.GetAllQuests()) // Loop through all active quests.
{
    string group = QuestLog.GetQuestGroup(quest);
    // Do something with 'quest' and 'group'.
}
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

Re: FindValue for enum Fields

Post by Mackerel_Sky »

Hey Tony,

Thanks for the tips - was able to get this to work using the code below:

Code: Select all

        foreach (var quest in DialogueManager.masterDatabase.items)
        {
            if (quest.IsItem) continue;
            if (quest.LookupValue("Group") == "Main" && QuestLog.GetQuestState(quest.Name) == QuestState.Active)
            {
                activeQuest = quest.Name;
                return quest.Name;
            }
        }
        return null;
Do you reckon this'll lead to any problems if I have a lot of main and side quests implemented?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: FindValue for enum Fields

Post by Tony Li »

Hi,

That's fine, and performance should be fine. If you're going to be creating new quests at runtime, loop through QuestLog.GetAllQuests() instead of DialogueManager.masterDatabase.items. But if you know that the only quests will be the ones defined in the database, your code is more performant.
Post Reply