Preventing Button From Being Clicked And Calling My Own Code Instead

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
EntertainmentForge
Posts: 23
Joined: Sun Nov 29, 2020 8:50 pm

Preventing Button From Being Clicked And Calling My Own Code Instead

Post by EntertainmentForge »

Hey Tony,

This issue is easier explain through video so I made a quick one:


(after you see the video)
Overall I'd like to call my own function, test if reward is selected, and based on that tell DialogueSystem if it should accept the button click or if it should call my other function that pops up the warning instead. What would be a way for doing that?
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Preventing Button From Being Clicked And Calling My Own Code Instead

Post by Tony Li »

Hi,

There are a few ways you can do it. Here are some ideas:

- Add two "No problem" nodes.
  • On one, set Conditions to check if the reward is selected. If so, run CollectEventRewards().
  • On the other, set Conditions to check if the reward is not selected. If so, say "Select a reward first".
  • When the player selects or deselects a reward, call DialogueManager.UpdateResponses().
- Or tick the Dialogue Manager's Input Settings > Include Invalid Response checkbox, and optionally set [em#] Tag For Invalid Responses. This will show the button in a disabled (non-clickable) state. You can use the Hover example on the Extras page to show a message when the player hovers on the disabled button. This post contains information that explains how to only show specific invalid responses.

- Or make a subclass of StandardUIResponseButton. Override the OnClick() method to check a condition and only call base.OnClick() if the condition is true. You could add a custom field to dialogue entries containing a Lua condition, and evaluate this field in your OnClick() method. You could add another custom field to contain a message to show if it evaluates false.
EntertainmentForge
Posts: 23
Joined: Sun Nov 29, 2020 8:50 pm

Re: Preventing Button From Being Clicked And Calling My Own Code Instead

Post by EntertainmentForge »

Thanks, Tony!

I think the StandardUIResponseButton override will do the trick. But I've been struggling with one more thing this whole time that I have to ask about:
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Preventing Button From Being Clicked And Calling My Own Code Instead

Post by Tony Li »

Hi,

The Dialogue System is in the special folder "Plugins".

Scripts in the Plugins folder compile first. They do not have access to scripts that are outside Plugins.

Scripts that are outside Plugins compile after that. They have access to scripts that are inside Plugins.

Put your subclasses in a folder that it outside of Plugins, such as Assets / MyGame / Scripts.
EntertainmentForge
Posts: 23
Joined: Sun Nov 29, 2020 8:50 pm

Re: Preventing Button From Being Clicked And Calling My Own Code Instead

Post by EntertainmentForge »

Thanks! This solved it :)
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Preventing Button From Being Clicked And Calling My Own Code Instead

Post by Tony Li »

Happy to help!
Post Reply