Activate next quest node

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

Activate next quest node

Post by shortestyard57 »

I am attempting to write a debug command that would allow me to step through a quest. Is there a method that progresses a quest one node? Looked on the forum and API but no luck so far.
User avatar
Tony Li
Posts: 22098
Joined: Thu Jul 18, 2013 1:27 pm

Re: Activate next quest node

Post by Tony Li »

Hi,

Yes, you can either:

1. Cause the conditions to be true -- for example, call MessageSystem.SendMessage() if the conditions are waiting for a message.

2. Or manually set a node's state by calling QuestMachine.SetQuestNodeState().
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Activate next quest node

Post by shortestyard57 »

Is there a way to do it without having to specify the quest node ID? For example, I am hoping to create a debug function that will accept the quest ID as the input and then regardless which node it is on, progress to the next linked node. If the nodes are indexed then move from node n to node n + 1.
User avatar
Tony Li
Posts: 22098
Joined: Thu Jul 18, 2013 1:27 pm

Re: Activate next quest node

Post by Tony Li »

Hi,

That would be fine if all quests were entirely linear. But Quest Machine is more flexible than that. Your quests can branch, or even loop back on themselves. To do it properly in these cases, make a list of all nodes that are active. Then set them true.

Code: Select all

public void AdvanceQuest(Quest quest)
{
    var activeNodes = quest.nodeList.FindAll(node => node.GetState() == QuestNodeState.Active);
    activeNodes.ForEach(node => node.SetState(QuestNodeState.True));
}
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Activate next quest node

Post by shortestyard57 »

Is there a way to get the Quest class by its string name?
User avatar
Tony Li
Posts: 22098
Joined: Thu Jul 18, 2013 1:27 pm

Re: Activate next quest node

Post by Tony Li »

Hi,

What do you mean by quest class?
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Activate next quest node

Post by shortestyard57 »

Sorry I mean the Quest asset by its quest ID.

This is the method I am working on.

Code: Select all

 public void AdvanceQuest(string questName)
    {
        string[] currentQuests = QuestLog.GetAllQuests();
        for (int i = 0; i < currentQuests.Length; i++)
        {
            if(questName == currentQuests[i])
            {                                
                Quest quest = //get Quest asset with the string name.
            }
        }

        var activeNodes = quest.nodeList.FindAll(node => node.GetState() == QuestNodeState.Active);
        activeNodes.ForEach(node => node.SetState(QuestNodeState.True));
    }
shortestyard57
Posts: 29
Joined: Fri Jun 02, 2023 8:31 am

Re: Activate next quest node

Post by shortestyard57 »

I found GetQuestInstance() that should work if I understand it correctly.

Code: Select all

public void AdvanceQuest(string questName)
    {
        PixelCrushers.QuestMachine.Quest quest = null;

        string[] currentQuests = QuestLog.GetAllQuests();
        for (int i = 0; i < currentQuests.Length; i++)
        {
            if (questName == currentQuests[i])
            {
                quest = QuestMachine.GetQuestInstance(currentQuests[i]);
            }
        }
        
        if (quest == null) { return; }

        var activeNodes = quest.nodeList.FindAll(node => node.GetState() == QuestNodeState.Active);
        activeNodes.ForEach(node => node.SetState(QuestNodeState.True));
    }
User avatar
Tony Li
Posts: 22098
Joined: Thu Jul 18, 2013 1:27 pm

Re: Activate next quest node

Post by Tony Li »

Hi,

Yes, that's correct. You can control most Quest Machine things using the QuestMachine class.
Post Reply