Set Quest state from script?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Set Quest state from script?

Post by timbecile »

I'm sure this has been asked a bunch, but I couldn't find it anywhere in the search.

What I'm trying to do is set the quest state from a c# script that's triggered after all the spawned enemies have been killed.

How do I do that?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Quest state from script?

Post by Tony Li »

Hi,

To set the quest state from a C# script, use QuestLog.SetQuestState:

Code: Select all

using PixelCrushers.DialogueSystem;
...
QuestLog.SetQuestState("My Quest", QuestState.Success);
A common way to trigger something after all the spawned enemies have been killed is to add an Increment On Destroy and Quest Trigger (or, more generally, Dialogue System Trigger) to each enemy:
  • Increment On Destroy will increment a variable. Configure its OnIncrement() event to call the Quest Trigger's OnUse method.
  • Set the Quest Trigger's trigger dropdown to OnUse, and set its Condition to require that the variable is greater than or equal to the number of spawned enemies. If so, set the quest state.
Using this technique, you don't need a C# script.
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: Set Quest state from script?

Post by timbecile »

Thanks Tony!

Is there a way at runtime to see what state a quest is in?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Quest state from script?

Post by Tony Li »

Yes, lots of ways. :-) If you're playing in the Unity editor, open the Dialogue Editor window and click on the Watches tab. Then add a watch on the quest.

If you're in a build, add a Lua Console to the Dialogue Manager. During play, press ~+L to open the Lua Console, and enter:

Code: Select all

return CurrentQuestState("My Quest")
where My Quest is the name of your quest.

In a script, check QuestLog.GetQuestState("My Quest").

And of course you can always set up a quest log window or quest tracker HUD so the player can check the state of quests.
Post Reply