Monitoring quests with LuaObserver

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
natsuha
Posts: 11
Joined: Fri Aug 13, 2021 9:28 am

Monitoring quests with LuaObserver

Post by natsuha »

The following code uses LuaObserver to monitor variables and quest states, and execute common delegates

code_luaObserver.png
code_luaObserver.png (16.88 KiB) Viewed 552 times

There are two questions.
1. Is it correct to use this code to monitor multiple variables and do the same thing?

2. The delegate is not executed when the quest is changed. Is there a wrong way to write it?

Thank you in advance for your help.
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Monitoring quests with LuaObserver

Post by Tony Li »

Hi,

That's fine to observe the variable value. Since you've set the frequency to EndOfConversation, it will only check the value at the end of conversations, which is efficient.

To observe the quest state, change the expression to: Quest['FindtheFirstKey'].State

Alternatively, you can add a script to the Dialogue Manager that has an OnQuestStateChange(title) method, or add a Dialogue System Events component and use the OnQuestStateChange() UnityEvent.
natsuha
Posts: 11
Joined: Fri Aug 13, 2021 9:28 am

Re: Monitoring quests with LuaObserver

Post by natsuha »

I was able to run the delegate even when I changed the Quest!
However, when I delete the delegate, I get an error.

luaObserver_errorlog.png
luaObserver_errorlog.png (23.72 KiB) Viewed 537 times

The order of "AddLuaObserver" changes the way the error occurs.

If I write Quest first, an error occurs when I delete the variable when it changes.
luaObserverQuest.png
luaObserverQuest.png (4.54 KiB) Viewed 537 times

When Variable is written first, an error occurs if it is deleted when the quest changes.
luaObserverVariable.png
luaObserverVariable.png (4.55 KiB) Viewed 537 times
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Monitoring quests with LuaObserver

Post by Tony Li »

Hi,

By "delete the delegate" do you mean DialogueManager.RemoveLuaObserver?

Would you please click on the error, press Ctrl+C (Cmd+C on Mac) to copy it to the clipboard, and paste it into a reply? This will help me confirm what I think the error is so I can provide a fix.
natsuha
Posts: 11
Joined: Fri Aug 13, 2021 9:28 am

Re: Monitoring quests with LuaObserver

Post by natsuha »

Yes, I get an error when I run DialogueManager.RemoveLuaObserver.

Code: Select all

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <695d1cc93cca45069c528c15c9fdd749>:0)
PixelCrushers.DialogueSystem.LuaWatchList.NotifyObservers () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Utility/LuaWatchList.cs:65)
PixelCrushers.DialogueSystem.LuaWatchers.NotifyObservers (PixelCrushers.DialogueSystem.LuaWatchFrequency frequency) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/LuaWatchers.cs:153)
PixelCrushers.DialogueSystem.DialogueSystemController.OnEndConversation (PixelCrushers.DialogueSystem.ConversationController endingConversationController) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/DialogueSystemController.cs:1302)
PixelCrushers.DialogueSystem.ConversationController.Close () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:174)
PixelCrushers.DialogueSystem.ConversationController.OnFinishedSubtitle (System.Object sender, System.EventArgs e) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:287)
PixelCrushers.DialogueSystem.ConversationView.FinishSubtitle () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:418)
PixelCrushers.DialogueSystem.ConversationView.HandleContinueButtonClick () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:390)
PixelCrushers.DialogueSystem.ConversationView.OnConversationContinue (PixelCrushers.DialogueSystem.IDialogueUI dialogueUI) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:373)
UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
PixelCrushers.DialogueSystem.AbstractDialogueUI:OnContinueConversation() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Abstract/Dialogue/AbstractDialogueUI.cs:366)
PixelCrushers.DialogueSystem.AbstractDialogueUI:OnContinue() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Abstract/Dialogue/AbstractDialogueUI.cs:356)
PixelCrushers.DialogueSystem.TextAnimatorContinueButtonFastForward:OnFastForward() (at Assets/Plugins/Pixel Crushers/Dialogue System/Third Party Support/Text Animator Support/TextAnimatorContinueButtonFastForward.cs:62)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:385)
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Monitoring quests with LuaObserver

Post by Tony Li »

Thank you. That confirms that issue. I'll provide a fix by tomorrow.
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Monitoring quests with LuaObserver

Post by Tony Li »

natsuha
Posts: 11
Joined: Fri Aug 13, 2021 9:28 am

Re: Monitoring quests with LuaObserver

Post by natsuha »

You work fast!
It worked exactly right!
Thank you!
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: Monitoring quests with LuaObserver

Post by Tony Li »

Glad to help! Thanks for confirming that it works in your project.
Post Reply