Disable certain responses after they have been selected

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable certain responses after they have been selected

Post by Tony Li »

Hi,

I forgot that the script looks directly at the field in the database, which contains the original design-time value of "Show Invalid". So it won't recognize that you've changed the runtime Lua value.

Here's an updated version that checks the runtime Lua value first:

ShowInvalidResponsesExample_2019-05-24a.unitypackage

Response "E" has this condition:

Code: Select all

Variable["AllowE"] == true
(When you click on "A", it sets the "AllowE" variable true.)

Response "E" has this script:

Code: Select all

Variable["AllowE"] = false;
Dialog[thisID].Show_Invalid = false
This makes "E" an invalid response again, and sets Show_Invalid to false.

I added comments to the script that should help explain the change.
Timeslip
Posts: 39
Joined: Fri Apr 05, 2019 6:31 am

Re: Disable certain responses after they have been selected

Post by Timeslip »

I replaced the script and configured it like your example. It's strange, because Dialog[thisID].Show_Invalid = false; just threw an error at first. Spent a few hours trying to figure out what was wrong and eventually wrote a method to change the field through code (which worked). Then went back to Dialog[thisID].Show_Invalid = false; and it worked.

Regardless of the means used to change the Show Invalid field, this error is thrown. It doesn't happen right away, but rather when the conversation returns to the hub (which links to the entry which allows you to heal the character). Not sure how serious it is, or if it even relates to Show Invalid. The bug may relate to the condition on the "Hub" being invalid.

Image

Code: Select all

Dialogue System: Lua code 'return Dialog[6].Show_Invalid' threw exception 'Lookup of field '6' in the table element failed because the table element itself isn't in the table.'
UnityEngine.Debug:LogError(Object)
PixelCrushers.DialogueSystem.Lua:RunRaw(String, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:219)
PixelCrushers.DialogueSystem.Lua:Run(String, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:120)
PixelCrushers.DialogueSystem.Lua:Run(String) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:139)
StandardDialogueUIShowInvalidResponses:AllowShowInvalid(Response) (at Assets/Dialogue System Examples/Show Invalid Responses Example/StandardDialogueUIShowInvalidResponses.cs:46)
StandardDialogueUIShowInvalidResponses:CheckInvalidResponses(Response[]) (at Assets/Dialogue System Examples/Show Invalid Responses Example/StandardDialogueUIShowInvalidResponses.cs:25)
StandardDialogueUIShowInvalidResponses:ShowResponses(Subtitle, Response[], Single) (at Assets/Dialogue System Examples/Show Invalid Responses Example/StandardDialogueUIShowInvalidResponses.cs:12)
PixelCrushers.DialogueSystem.ConversationView:StartResponses(Subtitle, Response[]) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:407)
PixelCrushers.DialogueSystem.ConversationController:OnFinishedSubtitle(Object, EventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:236)
PixelCrushers.DialogueSystem.ConversationView:FinishSubtitle() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:379)
PixelCrushers.DialogueSystem.ConversationView:HandleContinueButtonClick() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:351)
PixelCrushers.DialogueSystem.ConversationView:OnConversationContinue(IDialogueUI) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:336)
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.StandardUIContinueButtonFastForward:OnFastForward() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Effects/StandardUIContinueButtonFastForward.cs:67)
UnityEngine.EventSystems.EventSystem:Update()
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable certain responses after they have been selected

Post by Tony Li »

Hi,

The error is happening on dialogue entry 6, which is "Treat the fisherman's wounds" unless the IDs have changed since your post on Fri May 24.

As a test, what if you change the hub node's False Condition Action to Block, and tick the Group checkbox? I don't know that it will clear up the error, since I haven't been able to reproduce the issue here (my conversation may be set up slightly differently), but it will give us another data point.
Timeslip
Posts: 39
Joined: Fri Apr 05, 2019 6:31 am

Re: Disable certain responses after they have been selected

Post by Timeslip »

Hey, the ID for that entry is the same. Have done that, and changed the condition to true, which it should have been. Here's the error data. I should add that this error doesn't appear to be causing any (obvious) problems outside the error itself and it's working as intended now, so it's not a big deal.

Code: Select all

Dialogue System: Lua code 'return Dialog[6].Show_Invalid' threw exception 'Lookup of field '6' in the table element failed because the table element itself isn't in the table.'
UnityEngine.Debug:LogError(Object)
PixelCrushers.DialogueSystem.Lua:RunRaw(String, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:219)
PixelCrushers.DialogueSystem.Lua:Run(String, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:120)
PixelCrushers.DialogueSystem.Lua:Run(String) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:139)
StandardDialogueUIShowInvalidResponses:AllowShowInvalid(Response) (at Assets/Dialogue System Examples/Show Invalid Responses Example/StandardDialogueUIShowInvalidResponses.cs:46)
StandardDialogueUIShowInvalidResponses:CheckInvalidResponses(Response[]) (at Assets/Dialogue System Examples/Show Invalid Responses Example/StandardDialogueUIShowInvalidResponses.cs:25)
StandardDialogueUIShowInvalidResponses:ShowResponses(Subtitle, Response[], Single) (at Assets/Dialogue System Examples/Show Invalid Responses Example/StandardDialogueUIShowInvalidResponses.cs:12)
PixelCrushers.DialogueSystem.ConversationView:StartResponses(Subtitle, Response[]) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:407)
PixelCrushers.DialogueSystem.ConversationController:OnFinishedSubtitle(Object, EventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:236)
PixelCrushers.DialogueSystem.ConversationView:FinishSubtitle() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:379)
PixelCrushers.DialogueSystem.ConversationView:HandleContinueButtonClick() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:351)
PixelCrushers.DialogueSystem.ConversationView:OnConversationContinue(IDialogueUI) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:336)
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.StandardUIContinueButtonFastForward:OnFastForward() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Effects/StandardUIContinueButtonFastForward.cs:67)
UnityEngine.EventSystems.EventSystem:Update()
One thing I noticed is if I use Dialog[thisID].Show_Invalid = false instead of calling the method I wrote to do the same, an additional error is logged. This variable is set in the script section, just before Dialog[thisID].Show_Invalid = false - again not a big deal, mostly providing this info incase it is of any help.

Code: Select all

Dialogue System: Lua code 'Variable["TheDragFishermanAHealed"] = true;
Dialog[thisID].Show_Invalid = false;
' threw exception 'Lookup of field '6' in the table element failed because the table element itself isn't in the table.'
UnityEngine.Debug:LogError(Object)
PixelCrushers.DialogueSystem.Lua:RunRaw(String, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:219)
PixelCrushers.DialogueSystem.Lua:Run(String, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:120)
PixelCrushers.DialogueSystem.ConversationModel:GetState(DialogueEntry, Boolean, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:233)
PixelCrushers.DialogueSystem.ConversationModel:GetState(DialogueEntry) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:297)
PixelCrushers.DialogueSystem.ConversationController:OnSelectedResponse(Object, SelectedResponseEventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:257)
PixelCrushers.DialogueSystem.ConversationView:SelectResponse(SelectedResponseEventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:454)
PixelCrushers.DialogueSystem.ConversationView:OnSelectedResponse(Object, SelectedResponseEventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:447)
PixelCrushers.DialogueSystem.AbstractDialogueUI:OnClick(Object) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Abstract/Dialogue/AbstractDialogueUI.cs:346)
PixelCrushers.DialogueSystem.StandardDialogueUI:OnClick(Object) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardDialogueUI.cs:215)
UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
PixelCrushers.DialogueSystem.StandardUIResponseButton:OnClick() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardUIResponseButton.cs:124)
UnityEngine.EventSystems.EventSystem:Update()
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable certain responses after they have been selected

Post by Tony Li »

Thanks for the info. Unfortunately it's not enough to pinpoint the issue.

If you notice any problems or would like to get to the bottom of it anyway, please send a reproduction project to tony (at) pixelcrushers.com. I'll be happy to take a look any time.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable certain responses after they have been selected

Post by Tony Li »

I updated the example package:

ShowInvalidResponsesExample_2019-05-29.unitypackage

After changing the dialogue UI subclass script to work with the runtime Lua value of the "Show Invalid" field, I forgot to mention that it works best to tick the Dialogue Manager's Other Settings > Include SimStatus. This initializes the conversation's Dialog[] array, which allows this work without reporting an error message:

Code: Select all

Dialog[thisID].Show_Invalid = false
In the updated package, the example scene has "Include SimStatus" ticked, and the dialogue UI subclass has a new checkbox to omit SimStatus data from saved games. The default value of this checkbox omits SimStatus data from saved games to keep them smaller. To get rid of the error in your own project, you only need to import the dialogue UI subclass script from the example package.
gregsolo
Posts: 1
Joined: Mon Jun 03, 2019 11:43 am

Re: Disable certain responses after they have been selected

Post by gregsolo »

Hey!
That worked for me perfectly!

I have a question though: imagine you have a bit different scenario when you want to exclude invalid options by default and include some of them explicitly by turning on "Show Invalid" only when you need them. How can that be achieved?
My assumption was to untick the "Include Invalid Entries" of Dialogue Manager and use "Show Invalid" but that seems not to be working.

On that that note a bit architectural question: do we really need "Include Invalid Entries" option? Isn't "Show Invalid" enough and more flexible?

Thank you in advance!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable certain responses after they have been selected

Post by Tony Li »

Hi,

When preparing the response menu, the Dialogue System first evaluates all responses that the current node points to. It will create a list of responses whose Conditions are true. If the Dialogue Manager's Input Settings > Include Invalid Entries is ticked, the list will also include responses whose Conditions are false. So if you don't tick Include Invalid Entries, then invalid responses never even have a chance to be considered for the menu. So ticking Include Invalid Entries is mandatory in the scenario you describe.

Next, if you're using the StandardDialogueUIShowInvalidResponses script from the unity package above, the script removes invalid responses unless they have a "Show Invalid" field that's set to true.

In the example from the unity package above, the first step will create this list:
  • A
  • B (invalid) (Show Invalid is true)
  • C
  • D (invalid) (Show Invalid is false)
  • E (invalid) (Show Invalid is true)
The second step (the StandardDialogueUIShowInvalidResponses script) will remove D since its "Show Invalid" field is false:
  • A
  • B (invalid) (Show Invalid is true)
  • C
  • E (invalid) (Show Invalid is true)
In your scenario, add "Show Invalid" fields to any responses that you want to explicitly turn on, and set them to true. If you want a response to default to not being shown, don't add a "Show Invalid" field to it, or set the field to false.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable certain responses after they have been selected

Post by Tony Li »

Correction: In the example package, change line 55 to:

Code: Select all

var luaResult = Lua.Run("return Dialog[" + response.destinationEntry.id + "]. " + DialogueLua.StringToTableIndex(showInvalidFieldName));
hellwalker
Posts: 112
Joined: Tue Jan 19, 2016 11:37 pm

Re: Disable certain responses after they have been selected

Post by hellwalker »

Hey, has anything changed in newest DS that needs the code for this updated?
I'm getting this error:

Code: Select all

Dialogue System: Lua code 'return Dialog[25]. ShowInvalid' threw exception 'Lookup of field 'ShowInvalid' in the table element failed because the table element itself isn't in the table.'
But the ShowInvalid option with same spelling is on the problematic node:
Post Reply