Page 1 of 1
Monitoring quests with LuaObserver
Posted: Sun Dec 12, 2021 10:37 pm
by natsuha
The following code uses LuaObserver to monitor variables and quest states, and execute common delegates
- code_luaObserver.png (16.88 KiB) Viewed 660 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.
Re: Monitoring quests with LuaObserver
Posted: Mon Dec 13, 2021 8:24 am
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.
Re: Monitoring quests with LuaObserver
Posted: Mon Dec 13, 2021 10:10 am
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 (23.72 KiB) Viewed 645 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 (4.54 KiB) Viewed 645 times
When Variable is written first, an error occurs if it is deleted when the quest changes.
- luaObserverVariable.png (4.55 KiB) Viewed 645 times
Re: Monitoring quests with LuaObserver
Posted: Mon Dec 13, 2021 1:01 pm
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.
Re: Monitoring quests with LuaObserver
Posted: Mon Dec 13, 2021 3:56 pm
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)
Re: Monitoring quests with LuaObserver
Posted: Mon Dec 13, 2021 7:17 pm
by Tony Li
Thank you. That confirms that issue. I'll provide a fix by tomorrow.
Re: Monitoring quests with LuaObserver
Posted: Tue Dec 14, 2021 2:42 pm
by Tony Li
Re: Monitoring quests with LuaObserver
Posted: Wed Dec 15, 2021 12:24 am
by natsuha
You work fast!
It worked exactly right!
Thank you!
Re: Monitoring quests with LuaObserver
Posted: Wed Dec 15, 2021 8:10 am
by Tony Li
Glad to help! Thanks for confirming that it works in your project.