How to set the, intial state of a Quest (and other related thoughts)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

How to set the, intial state of a Quest (and other related thoughts)

Post by Hyrad »

Good day,
I'm having a challenge validating a condition through the dialogue editor: Quest["Find_something_to_kindle_fire"].State == "unassigned", which does not trigger at all. If I remove the condition, the quest works. I have tried to check the initial state of the quest by using QuestLog.GetAllQuests (QuestState.Unassigned) and the quest returns as such. I'm on a tight deadline so at this point I'm wondering a few things:

- How come I can't use the drop down box in the dialogue editor (Quest tab) to select any other state than none;
- Why does the quest return as "unassigned' through QuestLog.GetAllQuests and yet, why it doesn't comply with the condition?
Finally, I have implemented lua variable watching but it only shows me when the quest gets set to new.

And finally, I find that debugging and tracing lua code is very difficult, so I am looking at hooking my dialogs through C# code, that is, being able to use custom functions which would handle conditions so it's easier to trace what's doing what. Any pointers on the best way to do this?

Thanks a lot for your ongoing support,
-Jeff
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to set the, intial state of a Quest (and other related thoughts)

Post by Tony Li »

Hi Jeff,
Hyrad wrote:- How come I can't use the drop down box in the dialogue editor (Quest tab) to select any other state than none;
In the Dialogue Editor, the dropdown should also contain "unassigned", "active", "success", etc. If you import the Dialogue System into a new, empty project, does the dropdown work correctly? This will tell us if the problem is caused by a conflict in your current project.
Hyrad wrote:- Why does the quest return as "unassigned' through QuestLog.GetAllQuests and yet, why it doesn't comply with the condition?
What happens if you add a Lua Console to the scene, press ~+L to open it, and enter this:

Code: Select all

return Quest["Find_something_to_kindle_fire"].State
If it doesn't show "unassigned" exactly, it's probably related to the first problem above. I suspect a conflict is preventing the Dialogue System from setting quest states properly. Are there any errors in the Console window?
Hyrad wrote:And finally, I find that debugging and tracing lua code is very difficult, so I am looking at hooking my dialogs through C# code, that is, being able to use custom functions which would handle conditions so it's easier to trace what's doing what. Any pointers on the best way to do this?
Yes, register your C# code as Lua functions. From version 1.5.9 on, the Dialogue System registers 4 functions that are wrappers around the QuestLog class: (more info here)
  • CurrentQuestState(questName)
  • CurrentQuestEntryState(questName, entryNumber)
  • SetQuestState(questName, state)
  • SetQuestEntryState(questName, entryNumber, state)
So you can simplify your Conditions field to be more human-readable:

Code: Select all

CurrentQuestState("Find something to kindle fire") == "unassigned"
This is just FYI so you don't try to register functions with the same names. Here's an example script that registers a function ChangeQuestState(). This function changes a quest state and logs the change to the Console window:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class MyQuestFunctions : MonoBehaviour {

    void OnEnable() {
        Lua.RegisterFunction("ChangeQuestState", this, typeof(MyQuestFunctions ).GetMethod("ChangeQuestState"));
    }
        
    void OnDisable() {
        Lua.UnregisterFunction("ChangeQuestState");
    }
        
    public void ChangeQuestState(string questName, string newState) {
        var oldState = QuestLog.CurrentQuestState(questName);
        Debug.Log("CHANGING QUEST " + questName + " STATE FROM " + oldState + " TO " + newState);
        QuestLog.SetQuestState(questName, newState);
    }
}
Since you're under a tight deadline, please feel free to email me directly at tony (at) pixelcrushers.com any time. I'll also keep a close eye on the forum to reply back here.
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Re: How to set the, intial state of a Quest (and other related thoughts)

Post by Hyrad »

Hi Tony, as always, thanks for going beyond the call of duty on this one. I just created a new quest and now that I can set the initial state it works.
In the Dialogue Editor, the dropdown should also contain "unassigned", "active", "success", etc. If you import the Dialogue System into a new, empty project, does the dropdown work correctly? This will tell us if the problem is caused by a conflict in your current project.
For the first part, I deleted the assets directory, re-imported it and restarted Unity. The good news is that if I create a new quest i get to set the intial state; the bad news is that the quest I was trying to debug previously just dissapeared from the database. It's not too bad, I mean I can just re-create it (and this might be related directly or indirectly to the fact that I just updated the dialogue system) but I would like to avoid such a situation in the future. So I think for more safety I will export my database to CSV, would that be a viable solution to ensure that I make a backup?

As a side note, I just saw that I had a second dialog for the NPC which was not being found even though it existed (or at least it was showing up in the dialogue editor). I created a new one and the new one works fine. Sorry I cannot provide you with more specific info, but I'm including it in case it helps.
Yes, register your C# code as Lua functions.
Thanks for this information as well. I will use it to build my own quest system in the near future :)
Last edited by Hyrad on Tue Mar 14, 2017 3:50 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to set the, intial state of a Quest (and other related thoughts)

Post by Tony Li »

Hi,

Updating your version of the Dialogue System shouldn't cause any issues, as the dialogue database format hasn't changed in a long time. But it sure doesn't hurt to make backups. CSV or Chat Mapper XML formats are both fine to make backups. You don't need Chat Mapper itself if you're just using it as a backup format.
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Re: How to set the, intial state of a Quest (and other related thoughts)

Post by Hyrad »

Ok, my trouble started when I tried to re-import the database, but I made a lot of manipulations so perhaps it's just me. Thanks for the info.
Post Reply