Current Tracked Quest

Announcements, support questions, and discussion for Quest Machine.
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Current Tracked Quest

Post by shortestyard57 »

Is there a simple way to get the journal's currently tracked quest? I have a script listening to tracked toggle changes via

Code: Select all

MessageSystem.AddListener(this, QuestMachineMessages.QuestTrackToggleChangedMessage, string.Empty);
but it doesn't active when receiving the quest only when I change the tracked status in the journal.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Current Tracked Quest

Post by Tony Li »

Hi,

You can use this:

Code: Select all

var trackedQuest = QuestMachine.GetQuestJournal().questList.Find(quest => quest.showInTrackHUD);
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Current Tracked Quest

Post by shortestyard57 »

Thanks! that ended up giving me some object reference set error I couldn't figure out how to remove but it did lead me to find the event

Code: Select all

QuestMachine.GetQuestJournal().questAdded += QuestAdded;
which works for my needs.

However, hijacking my own thread a bit, I am having a confusing result from

Code: Select all

MessageSystem.AddListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty);
I am integrating with Dialogue System and in the dialogue I have scripts as

Code: Select all

SetQuestState("fetchQuest", "Success")
Also tried

Code: Select all

SetQuestNodeState("fetchQuest", "Return", "True")
and

Code: Select all

SetQuesterQuestNodeState("fetchQuest", "Return", "True", "Player")
However, using debug logs it seems to produce the quest ID, null node info, and "inactive" as the final message. What I was anticipating it doing is producing changed messages for each node up to quest success like it does when I start the quest with

Code: Select all

GiveQuestToQuester("Shop Keeper", "fetchQuest", "Player");
Overall, it is being used in a script that sets ORK Global bools of questIDTracked, questIDState, questIDNodeIDState

Code: Select all

    [SerializeField] private QuestVariablesSchematicsDictionary dictionary;
    private MakinomSchematicAsset schematicAsset;
    private List<PixelCrushers.QuestMachine.Quest> trackedQuests;
    //private List<string> trackedQuestIDs;

    private void Awake()
    {
        //Message with paremeter = questID, Argument 0 = nodeID, argument 1 = new state
        QuestMachine.GetQuestJournal().questAdded += QuestAdded;
        MessageSystem.AddListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty);        
    }

    private void QuestAdded(PixelCrushers.QuestMachine.Quest quest)
    {
        Maki.Game.Variables.Set(quest.id + "Tracked", true);
        Debug.Log("Tracked Quest true");
    }

    private void OnDestroy()
    {
        // Stop listening:
        MessageSystem.RemoveListener(this);
        QuestMachine.GetQuestJournal().questAdded -= QuestAdded;
        //QuestMachine.GetQuestJournal().
    }

    public void OnMessage(MessageArgs messageArgs)
    {
        string questID = messageArgs.parameter;
        
        StringField nodeIDField = (StringField)messageArgs.values[0];
        
        //This will remove messages pertaining to queststates and not quest not states
        //if (nodeIDField == null) { return;}

        string nodeID = StringField.GetStringValue(nodeIDField);        

        //seems to work regardless of questnodestate or queststate message arguement
        QuestNodeState state = (QuestNodeState)messageArgs.values[1];
        string status = state.ToString();        

        string globalVariable = questID + nodeID + status;
        Debug.Log(globalVariable);

        //set node state variables to true
        if (dictionary.QuestSchematicsDictionary.ContainsKey(globalVariable))
        {
            Maki.Game.Variables.Set(globalVariable, true);
            
            //if quest is successful then change tracking
            if (globalVariable == questID + "Successful")
            {
                Maki.Game.Variables.Set(questID + "Tracking", false);
            }
        }
Is there something unique about setting the final node to true via dialogue system script that would alter the flow of node change messages?
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Current Tracked Quest

Post by shortestyard57 »

https://imgur.com/a/m6zlQaG

Here are screen shots from the console and the quest itself. Is "5" normal as a quest or node state as seen on the quest given line?

It also isnt doing any of the action in the "Return" node even if its set directly as true in dialogue.
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Current Tracked Quest

Post by shortestyard57 »

So I played around with the debug options in the Quest Machine Config component and this is what I got https://imgur.com/a/DWKeJcp

It appears to be registering the quests again instead of setting the node state starting with the 17:48:22 line. I am going through my set up to see if anything is causing a crash but any other ideas?
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Current Tracked Quest

Post by Tony Li »

We can dig into what's going on here, or we can get things working the way you want. Either way, I may need a bit more info.

It sounds like the end result is that you want three ORK global bools -- questIDTracked, questIDState, and questIDNodeIDState -- to be kept up to date with the current tracked quest and its current state (i.e., the node that's currently active). Is that correct?

If so, then I recommend just adding listeners for QuestMachine.QuestTrackToggleChangedMessage and QuestMachine.QuestStateChangedMessage. Handle them in your OnMessage() method like:

Code: Select all

public void OnMessage(MessageArgs messageArgs)
{
    switch (messageArgs.message)
    {
        string questID = messageArgs.parameter;
        
        case QuestMachineMessages.QuestTrackToggleChangedMessage:
            Maki.Game.Variables.Set(questID + "Tracking", (bool)messageArgs.values[0]);
            break;
            
        case QuestMachineMessages.QuestStateChangedMessage:
            bool isMainQuestState = messageArgs.values[0] == null;
            if (isMainQuestState)
            {
                QuestState questState = (QuestState)messageArgs[1];
                string  questStateVariableName = questID + questState;
                Maki.Game.Variables.Set(questStateVariableName, true); // I'm not quite sure why this would be a bool.
            }
            else
            {
                string questNodeID = (StringField)messageArgs[0];
                QuestNodeState questNodeState = (QuestNodeState)messageArgs[1];
                string questNodeStateVariableName = questID + questNodeID + questNodeState;
                Maki.Game.Variables.Set(questNodeStateVariableName, true);
            }
            break;
    }
}
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Current Tracked Quest

Post by shortestyard57 »

Correct on the three variables and yes you're right questIDState makes more sense as a string instead of a bool. Thanks for showing me the switch, I was wondering how to combine multiple messages in one script. I implemented it as you suggested however, it still seems to not be completing the quests and registering all the quests again.

Code: Select all

    public void OnMessage(MessageArgs messageArgs)
    {
        string questID = messageArgs.parameter;

        switch (messageArgs.message)
        {
            case QuestMachineMessages.QuestTrackToggleChangedMessage:
                Maki.Game.Variables.Set(questID + "Tracking", (bool)messageArgs.values[0]);
                break;

            case QuestMachineMessages.QuestStateChangedMessage:
                bool isMainQuestState = messageArgs.values[0] == null;
                if (isMainQuestState)
                {
                    QuestState questStateAsset = (QuestState)messageArgs.values[1];
                    string questState = questStateAsset.ToString();

                    //string questStateVariableName = questID + questState;
                    Maki.Game.Variables.Set(questID, questState); // I'm not quite sure why this would be a bool.
                }
                else
                {
                    string questNodeID = StringField.GetStringValue((StringField)messageArgs.values[0]);
                    QuestNodeState questNodeState = (QuestNodeState)messageArgs.values[1];
                    string questNodeStateVariableName = questID + questNodeID + questNodeState;
                    Maki.Game.Variables.Set(questNodeStateVariableName, true);

                    //PlaySchematic(questNodeStateVariableName);
                }
                break;
        }
    }
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Current Tracked Quest

Post by Tony Li »

Hi,

I don't understand. Do you want your script to change a quest state in Quest Machine?

Or do you want your script to change some ORK variable differently?

Or are you not receiving the correct messages from Quest Machine?

Or something else?

(I'm finishing work for the night. I'll check back first thing in the morning.)
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Current Tracked Quest

Post by shortestyard57 »

The variables are being set correctly as far as I can tell. They will be used to allow ORK Schematics to check the quest state, which I got working. The issue I’m having is that when I try and complete a quest in Dialogue System conversations using SetQuestNode or SetQuest as shown in my earlier message it seems to cause a re registering of the quests (both quests in the database not just the one I am attempting to progress) instead of setting the node to True or Quest to successful and the corresponding actions in the Quest aren’t triggered. The quest machine debug log showing that is in my second message with a link.

Using the script that listens to the quest node state change messages as a debugger as well, the last message seems to be the last node that was active but now Inactive instead of True.

Thanks for your help.

Edit: after sleeping on it but can’t test until after work today, can mixing the scripts specifying quester and not specifying like GiveQuest and GiveQuestToQuester cause issues with quest instances?
Other thought is my Journal is located on the same object as the quest machine component since it was giving duplicate Journal ID errors on my switchable playable characters objects and when changing scenes if it was on a separate scene object.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Current Tracked Quest

Post by Tony Li »

Hi,

If there's only one QuestJournal component in all of the open scenes, then GiveQuest() and GiveQuestToQuester() will be functionally the same, as long as GiveQuestToQuester() specifies the ID of the QuestJournal. If GiveQuestToQuester() specifies an ID of a QuestJournal that isn't present, it won't be able to give the quest.
Post Reply