Multiple stat conditions with multiple menu texts, all in one button.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Multiple stat conditions with multiple menu texts, all in one button.

Post by Abelius »

Hi there,

I have a fairly complex situation I can't figure out...

I'm setting up an item "on click" conversation. It's a bed, and it'll have three options:
- Sleep
- Playing the guitar :roll:
- Exit

What I want is that if the conditions for an option aren't met, it should mark the menu entry as invalid, using its assigned Em tag and setting the button to non-interactable.

But... I also want the menu text being different when invalid, and that's the tricky part.

The Sleep option was easy. As I only want it to check if it's the evening or not, I just needed do this...:

Image

...and set up the same conditional, setting the valid one to not show when invalid:

Image
Image

...and they're evaluated in that order. All good.

The problem that I have is with the other option...

Let's say that I have an... ahem, 'Guitar Skills' stat, and an "Inspiration" stat. :P Now, I want that if the character doesn't have enough guitar skills, the menu text in that option is "??? (not enough skill)".

And later on, when she reaches the required skill, another check is made to see if she has enough Inspiration points, to actually play. And if she doesn't, the menu text would turn into "Play the guitar (not enough inspiration), and also be shown as invalid.

Only if both stat requirements are met, the menu text "Play the guitar" should be shown as a valid button to press.

So, I tried doing the same as before, putting the Guitar Skills check on the top, then the Inspiration check next, and finally the valid option that should appear only when both stats are enough.

The problem is, even if the Guitar Skill check is done at first, the Inspiration check overwrites the Guitar Skill, which should always take precedence because I want to keep a secret the... instrument she's gonna play until she has the skill. :roll:

So, I went and inverted both skill check nodes, so the Guitar Skills are the second. But now I have the issue that if she has enough skill, but NOT enough inspiration, the third valid option is not shown, and the second one "??? (not enough skill)" is shown as a valid button to press.

And that's my roadblock...: I'm adding nodes that I ONLY want to show up when they're invalid.

Or in other words: I'd need the opposite to the field 'Show Invalid'. That is, a 'Show Valid' field I could set to false in those <put here what you would have needed> menu text entries. :lol:

Is what I want to do so complex that I indeed would need that field? Or this could be done in another way? I'm really confused... :?
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Multiple stat conditions with multiple menu texts, all in one button.

Post by Tony Li »

In this case, it might be easier to manually mark nodes as invalid -- for example, by putting a special tag of your choosing such as "{invalid}" in the text and processing it at runtime. Your conversation might look like this:

guitar1.png
guitar1.png (22.25 KiB) Viewed 540 times

Or, if you want to organize it into groups, like this:

guitar2.png
guitar2.png (35.45 KiB) Viewed 540 times

Either way, notice that it doesn't use [position=#] tags, and the invalid responses have "{invalid}" in their text. Instead, you can use a script like this to process the responses before they're shown:

HandleInvalidTags.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class HandleInvalidTags : MonoBehaviour
{
    public void OnConversationResponseMenu(Response[] responses)
    {
        // If any responses' text contains "{invalid}", make the response invalid:
        foreach (Response response in responses)
        {
            string text = response.formattedText.text;
            if (text.Contains("{invalid}"))
            {
                text = text.Replace("{invalid}", string.Empty); // Remove "{invalid}"
                // This next line applies the Em Tag For Invalid Responses formatting:
                text = string.Format("[em{0}]{1}[/em{0}]", (int)DialogueManager.displaySettings.inputSettings.emTagForInvalidResponses, text);
                response.formattedText.text = FormattedText.Parse(text).text;
                response.enabled = false; // This means it's invalid and not clickable.
            }
        }
    }
}
The nodes' Conditions are set so that they're true if they should be shown (even if they're invalid). For example, the "{invalid}Guitar (not inspired)" node's Conditions require that the player has the guitar skill but her inspiration is too low.
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Multiple stat conditions with multiple menu texts, all in one button.

Post by Abelius »

Hi Tony,

I'm afraid I don't fully understand.

I've added the script to the DS Controller game object, then I've set two groups with child entries, and set them up like this..:

Image

Now, this paragraph is the one I don't understand...:
Tony Li wrote: Tue Oct 19, 2021 11:19 pm The nodes' Conditions are set so that they're true if they should be shown (even if they're invalid). For example, the "{invalid}Guitar (not inspired)" node's Conditions require that the player has the guitar skill but her inspiration is too low.
I've set that that node in particular like this...:

Image

Also set up the rest of the {invalid} tagged nodes like that (checking for a "not enough xxx" condition and setting them up to show them if invalid.

But this is what I get when both stats are at zero and it is the evening...:

Image

That is, the only node not showing up is the one that doesn't meet their conditions and its 'Show Invalid' field is set to False (Play guitar).

It should have shown just "Sleep", "??? (Skill 10+)", and "Exit".

And if I try with all nodes set 'Show Invalid' to False, only "Sleep" and "Exit" nodes are shown.

So, I guess this could be a combo of me not having interpreted your instructions correctly, and maybe the 'HandleInvalidTags' script not being applied (?).
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Multiple stat conditions with multiple menu texts, all in one button.

Post by Tony Li »

Hi,

Here's an example:

DS_AbeliusInvalidExample_2021-10-20.unitypackage

The scene has input fields that you can set for Skill and Inspiration, and a toggle for Night/Day. Then click Start Conversation. (The condition for Guitar is Skill > 0 and Inspiration >= 50.)

Note that the Dialogue Manager's 'Include Invalid Responses' is UNticked. Instead, the HandleInvalidTags scripts converts any responses whose text contains "{Invalid}" into invalid responses before showing them in the menu.
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Multiple stat conditions with multiple menu texts, all in one button.

Post by Abelius »

Tony Li wrote: Wed Oct 20, 2021 10:45 am Note that the Dialogue Manager's 'Include Invalid Responses' is UNticked. Instead, the HandleInvalidTags scripts converts any responses whose text contains "{Invalid}" into invalid responses before showing them in the menu.
Oh lol, that was the issue. :lol:

I had 'Include Invalid Responses' checked in the DS Controller.

Now it's working flawlessly and pretty. Thank you!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Multiple stat conditions with multiple menu texts, all in one button.

Post by Tony Li »

Glad to help!

If you're relying on 'Include Invalid Entries' elsewhere, you can keep that checkbox ticked on the Dialogue Manager and override its value for this specific conversation by setting the overrides in the conversation's properties.
Post Reply