Page 1 of 3
Disable certain responses after they have been selected
Posted: Tue May 21, 2019 12:33 pm
by Timeslip
Hi Tony,
My game has a number of skill checks and these are shown, even if the player lacks the requirements to select them. For the most part, I'd like to allow players to revisit dialogue, but in the case when a response results in an action (like healing an NPC), I'd like to have that response removed. Can you offer any suggestions for this?
Re: Disable certain responses after they have been selected
Posted: Tue May 21, 2019 1:43 pm
by Tony Li
Hi,
Use the response's Conditions field for this. If the Conditions are false, the response will not be shown.
Since you only want to hide certain responses, variables are one way to do it. For example, in the Dialogue Editor's Variables section you can add a new variable named "HealedNPC".
Then configure the response node similarly to this:
- Dialogue Text: "I heal you!"
- Conditions: Variable["HealedNPC"] ~= true
- Script: Variable["HealedNPC"] = true
For Conditions and Script, you don't have to type in the text manually. You can click "..." to reveal dropdown menus.
You can also
register your own script methods with the Dialogue System and use them in Conditions and Script fields.
Re: Disable certain responses after they have been selected
Posted: Fri May 24, 2019 10:05 am
by Timeslip
Hi Tony,
Since I'm trying to show options which are not available based on the player's current stats and skills, (so the player knows there are other options), I've ticked the show invalid entries option. This seems to prevent the solution from working.
Re: Disable certain responses after they have been selected
Posted: Fri May 24, 2019 10:32 am
by Tony Li
A short subclass of StandardDialogueUI will do the trick, as described in
this post. The example in that post is for version 1.x of the Dialogue System and UnityUIDialogueUI. This version is updated for 2.x and StandardDialogueUI:
ShowInvalidResponsesExample_2019-05-24.unitypackage
Re: Disable certain responses after they have been selected
Posted: Fri May 24, 2019 11:21 am
by Timeslip
In reference to step 2:
2. Replaced the Unity UI Dialogue UI component with Unity UI Dialogue UI Show Invalid Responses. To do this, I changed the Inspector to Debug mode using the three-bar menu in the top right of the Inspector. Then I dragged UnityUIDialogueUIShowInvalidResponses.cs onto the Script field, replacing UnityUIDialogueUI. This replaced the script while keeping all the UI element assignments intact. Then I switched the Inspector back to Normal mode using the three-bar menu:
Which object should UnityUIDialogueUI be replaced on?
Re: Disable certain responses after they have been selected
Posted: Fri May 24, 2019 11:26 am
by Tony Li
Hi,
Timeslip wrote: ↑Fri May 24, 2019 11:21 amWhich object should UnityUIDialogueUI be replaced on?
The dialogue UI GameObject. It sounds like you did it perfectly. BTW, those instructions were written for Dialogue System version 1, which didn't have StandardDialogueUI. So the version 1 example and script use the older UnityUIDialogueUI. If you're using the newer StandardDialogueUI, as the built-in Dialogue Manager prefab does, use the script I provided in the updated package above.
Re: Disable certain responses after they have been selected
Posted: Fri May 24, 2019 1:18 pm
by Timeslip
It's working now, but seems that I need to change the state of the dialogue entry field "show invalid" from true to false once the option has been selected.
This is the behaviour I'm trying to get.
[Player lacks skill to heal & character not healed] -> response is invalid, but visible
[Player has skill to heal & character not healed] -> show as valid response
[Character has been healed] -> response is invisible
Re: Disable certain responses after they have been selected
Posted: Fri May 24, 2019 1:34 pm
by Timeslip
Nevermind, think I have it figured out. Will post again if can't figure it. Leaving this here in case it's any use to someone else. Thanks for help!
Code: Select all
DialogueEntry dialogueEntry = dialogueDatabase.GetDialogueEntry(conversationIDIn, dialogueEntryIn);
Field.SetValue(dialogueEntry.fields, "Show Invalid", false);
Re: Disable certain responses after they have been selected
Posted: Fri May 24, 2019 1:37 pm
by Tony Li
You don't have to write any code. Another solution is to set the response's Script field to:
Code: Select all
Dialog[thisID].Show_Invalid = false
Re: Disable certain responses after they have been selected
Posted: Fri May 24, 2019 7:00 pm
by Timeslip
Still stuck on this. Getting this error message:
Code: Select all
Dialogue System: Lua code '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()
This is how the dialogue entry is set up.