Page 1 of 1

Disable a specific response button

Posted: Fri Sep 06, 2024 2:50 pm
by jonathancarroll
Hello, I'd like to set a specific response option's button to be disabled, ie interactable = false, if a certain condition is met.
Wondering how to write the LUA to do this.
I want the player to be able to see that they can't choose the option, so I'd be setting a specific "disabled" color in the button component.
Thanks!

Re: Disable a specific response button

Posted: Fri Sep 06, 2024 3:09 pm
by Tony Li
Hi,

Set that dialogue entry's Conditions. For example:
  • Menu Text: "Buy a laser pistol [50 credits]"
  • Conditions: Variable["Credits"] >= 50
Then tick the Dialogue Manager GameObject's Display Settings > Input Settings > Include Invalid Entries. This will tell the Dialogue System to include response buttons for entries whose Conditions are false, but it will make them non-interactable.

You can also set the [em#] Tag for Invalid Entries dropdown to show the response button's text in a specific emphasis setting value by automatically adding [em#] markup tags.

If you only want to have "Include Invalid Entries" behavior for certain invalid entries but not others, see this post.

Re: Disable a specific response button

Posted: Sat Sep 07, 2024 11:18 am
by jonathancarroll
Thank you so much!

Re: Disable a specific response button

Posted: Sat Sep 07, 2024 11:37 am
by Tony Li
Happy to help!

Re: Disable a specific response button

Posted: Fri Oct 18, 2024 6:27 am
by ds2497
Tony Li wrote: ↑Fri Sep 06, 2024 3:09 pm Hi,

Set that dialogue entry's Conditions. For example:
  • Menu Text: "Buy a laser pistol [50 credits]"
  • Conditions: Variable["Credits"] >= 50
Then tick the Dialogue Manager GameObject's Display Settings > Input Settings > Include Invalid Entries. This will tell the Dialogue System to include response buttons for entries whose Conditions are false, but it will make them non-interactable.

You can also set the [em#] Tag for Invalid Entries dropdown to show the response button's text in a specific emphasis setting value by automatically adding [em#] markup tags.

If you only want to have "Include Invalid Entries" behavior for certain invalid entries but not others, see this post.
Hi Tony, I'm following the 2019-05-29.unitypackage post and have 'Include SimStatus' checked, but I'm still getting an error. I noticed that the original post discussed this error later on, but the conversation ended when you were about to test it, with no further updates. For your information, my dialogue has some condition checks when linking to other dialogues... Any hints on how I can solve this?

Image
Image
Image

Re: Disable a specific response button

Posted: Fri Oct 18, 2024 12:49 pm
by Tony Li
Hi,

Can you back up your project, update to the current DS version, and check again?

If it still reports those errors, let me know.

Re: Disable a specific response button

Posted: Fri Oct 18, 2024 11:34 pm
by ds2497
Hi Tony, I've updated DS to version 2.2.48, but the same error still appears. Here are some screenshots from my dialogue settings. Please let me know if I need to provide any additional information to help you find the source of the problem.

This is the parent dialogue entry that links to other entries with conditions:
Image

This is one of the child entries that shows an error:
Image

By the way, I'm awared in the latest version, you solve the bug in if ConversationView from this post. Thank you so much for the hard work!

Re: Disable a specific response button

Posted: Sat Oct 19, 2024 10:59 am
by Tony Li
Hi,

Can you send a reproduction project to tony (at) pixelcrushers.com along with reproduction steps?

The error suggests that the wrong conversation has set the Dialog[] Lua variable.

At runtime, each conversation has a Lua table named Conversation[#] where # is the conversation ID. Inside this table is a sub-table named Dialog[#] where this # is the entry ID. So, for example, the SimStatus for conversation 7, dialogue entry 42 is in:

Code: Select all

Conversation[7].Dialog[42].SimStatus

When the Dialogue System's ConversationController gets to a dialogue entry, it sets the alias "Dialog[]" to that dialogue entry's conversation.

If you can't identify why this is happening, you could take a different approach and not use SimStatus at all. Instead, make and use a subclass of StandardUIMenuPanel that overrides the ShowResponses() method. Something like:

Code: Select all

public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout)
{
    var list = new List<Response>();
    foreach (var response in responses)
    {
        var showInvalid = Field.LookupBool(response.destinationEntry.fields, "Show Invalid");
        if (response.enabled || showInvalid) list.Add(response);
    }
    responses = list.ToArray();
    base.ShowResponses(subtitle, responses, timeout); //edit: fixed method call
}

Re: Disable a specific response button

Posted: Sun Oct 20, 2024 5:24 am
by ds2497
The overridden method ShowResponses works great! Just a small correction—the last line of the code should be written like this...

Code: Select all

base.ShowResponses(subtitle, responses, target);

Thank you so much for the help!

Re: Disable a specific response button

Posted: Sun Oct 20, 2024 8:36 am
by Tony Li
Thanks! I should have a keyboard macro that adds a "may have typos, etc." disclaimer on code examples that I type directly into forum replies. I'll fix that in my post above.