Showing AND hiding invalid entries in the same conversation (?)

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

Showing AND hiding invalid entries in the same conversation (?)

Post by Abelius »

Hello there,

I'm going like this...:

Image

I'm showing invalid responses (for reasons) AND using an Em tag for them.

But I'd also like to hide responses that are related to already turned in quests. For example...:

Image

"About Eri's task..." has a condition to be valid only if the related quest state is either 'success' or 'failure'...:

Image

And it continues with several nodes in which the quest is turned in and reset (set to 'Unassigned') for the following day (repeatable):

Image

Then, the last node returns to my conversation "hub" node, from which all the responses are (supposedly) evaluated again:

Image

Now... if I don't do anything more, this is what happens the second time the responses are shown...:

Image

The (now) invalid response is formatted according to Em1 tag settings.

All of this is the expected behavior, of course.

But thing is, in a situation like these I don't want those responses showing at all (in other cases I want them visible, yes...).

So I went and created a node before the responses hub, for calling this PlayMaker action...:

Image

It sets 'Include Invalid Entries' to disabled:

Image

So... my expectations were that for the remainder of the conversation (until I switch invalid responses on again, at the End node), the next responses evaluated as invalid would not be shown to the player... but they still are shown. :?

Am I doing something wrong here? Is this even possible...?

Please, note that in other parts of the conversation tree (outside the shown 'Hub') I'll need to show invalid responses always, so I'm afraid I can't use anything that overrides settings for the whole conversation...

Thank you for your time!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Showing AND hiding invalid entries in the same conversation (?)

Post by Tony Li »

Hi,

In How to format & disable responses based on variables/quest states?, you added a Show Invalid field to your dialogue entries:

Image

I recommend adding another field Show Conditions that contains some Lua conditions such as:

Code: Select all

CurrentQuestState("Clean Pot") == "active"
As in this updated package: ShowInvalidResponsesExample_2017-11-12.unitypackage

If Show Invalid is true, then it also checks Show Conditions. Ultimately Show Invalid is kind of redundant since setting Show Conditions to "true" or "false" has the same effect. But I left it in because it might make the logic easier to read.

Here's the updated script that's in the package:

Code: Select all

using UnityEngine;
using System.Collections.Generic;
using PixelCrushers.DialogueSystem;

public class UnityUIDialogueUIShowInvalidResponses : UnityUIDialogueUI
{

    public string showInvalidFieldName = "Show Invalid";
    public string showConditionsFieldName = "Show Conditions";

    public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout)
    {
        responses = CheckInvalidResponses(responses);
        base.ShowResponses(subtitle, responses, timeout);
    }

    private Response[] CheckInvalidResponses(Response[] responses)
    {
        if (!HasAnyInvalid(responses)) return responses;
        var list = new List<Response>();
        for (int i = 0; i < responses.Length; i++)
        {
            var response = responses[i];
            // Is Show Invalid true?
            if (response.enabled || Field.LookupBool(response.destinationEntry.fields, showInvalidFieldName))
            {
                // Show Invalid is true, so make sure "Show Conditions" are true:
                var conditions = Field.LookupValue(response.destinationEntry.fields, showConditionsFieldName);
                if (Lua.IsTrue(conditions))
                {
                    list.Add(response);
                }
            }
        }
        return list.ToArray();
    }

    private bool HasAnyInvalid(Response[] responses)
    {
        if (responses == null) return false;
        for (int i = 0; i < responses.Length; i++)
        {
            if (!responses[i].enabled) return true;
        }
        return false;
    }

}
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Showing AND hiding invalid entries in the same conversation (?)

Post by Abelius »

Mmm... actually, I didn't get past Step 1. in the thread you mention, because I wanted all invalid responses to be included back then... good thing you've reminded me of that! :lol:

Okay, I'll try to setup the thing as you say and get back to you. Thank you! :mrgreen:
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Showing AND hiding invalid entries in the same conversation (?)

Post by Tony Li »

Try out the included example scene first. It should make things clearer.
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Showing AND hiding invalid entries in the same conversation (?)

Post by Abelius »

It's working as I need now. Thanks!

However... is it normal that all the previously created nodes don't get the new fields?

I need to substitute the old response nodes, which I'm interested in setting the "Show Invalid" field to true or false, with a duplicated one. I guess this is normal considering they get it from a template, right? Not a big deal, just curious.

I still need to look into the other little problem I had with invalid responses still getting highlighted (you already replied to me on that one), but there's also another thing I'd like to know, that I guess is more or less related to this...

Is there some way to avoid a given response being formatted with 'Em Tag for Old Responses'...?

Thanks!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Showing AND hiding invalid entries in the same conversation (?)

Post by Tony Li »

Abelius wrote: Sun Nov 12, 2017 5:25 pm...is it normal that all the previously created nodes don't get the new fields?
Yes. To apply the template (i.e., add missing fields) to all existing nodes, click on the Templates tab and select Menu > Apply Template To Assets.
Abelius wrote: Sun Nov 12, 2017 5:25 pmIs there some way to avoid a given response being formatted with 'Em Tag for Old Responses'...?
Sure. Each node has a "SimStatus" value that can be one of these three values:
  • Untouched: Completely new
  • WasOffered: Was shown in a response menu but not clicked
  • WasDisplayed: Was clicked in a response menu or spoken by an NPC
If a node's SimStatus is WasDisplayed, it's an old response.

To reset the node back to Untouched, in a script call DialogueLua.MarkDialogueEntryUntouched(dialogueEntry).

If you want to do it through Lua, you need the conversation and node ID numbers. Then run this Lua code:

Code: Select all

Conversation[#].Dialog[#].SimStatus="Untouched"
where the #'s are the conversation and node IDs.

EDIT: I may have misunderstood what you want to do. If you want to prevent a node from ever being formatted with 'Em Tag for Old Responses', do this instead: In the node's Script field, add this:

Code: Select all

Dialog[#].SimStatus="Untouched"
where # is the node's ID. In the Script field, the Conversation[#] part is implied, so you can omit it. The code above will immediately set the node's SimStatus back to Untouched as soon as it's displayed.
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Showing AND hiding invalid entries in the same conversation (?)

Post by Abelius »

Awesome! What an easy an straightforward solution. 😊

It's the second case indeed, hehe...
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Showing AND hiding invalid entries in the same conversation (?)

Post by Tony Li »

Great! Glad to help!
Post Reply