Page 1 of 1

Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Sun Feb 12, 2023 3:05 pm
by laurelhach
Hi Tony,

I'd like to know if there is a way to trigger a script (or something else) at the end of the NPC conversation entry.
Let me explain: Right now, using the typewriter style to display the text, the script is executed when the NPC starts the dialogue. But I'd like to have the script trigger at the end of the entry (or when the typewriter is completed). Right now, the item is given to the player, but the NPC didn't even talk about it :)

Thanks in advance!

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Sun Feb 12, 2023 3:13 pm
by Tony Li
Hi,

Two ideas:

1. Add an empty node after that node, and give the item in the empty node, or

2. Give it using a sequencer command, and wait for the "Typed" message that the typewriter sends. Example:

Code: Select all

GiveItem(Magic Sword)@Message(Typed)
The example above assumes a custom sequencer command GiveItem().

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Mon Feb 13, 2023 1:43 pm
by laurelhach
So I tried the second option :
I've added this in the sequencer:

Code: Select all

GiveItem(item)@Message(TypeEnds)
And I've added in the typewrite an event on end

Code: Select all

    
    public void OnTextEnd()
    {
        Sequencer.Message("TypeEnds");
    }
The Message is sent (Validated with breakpoint), and the GiveItem method works (validated too) if I don't have the @Message(TypeEnds) at the end.
But having the @Message(TypeEnds) never triggers ...

Do you know what I could be doing wrong?

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Mon Feb 13, 2023 1:58 pm
by Tony Li
Hi,

If you're using the UnityUITypewriterEffect or TextMeshProTypewriterEffect (or a TextAnimatorSubtitlePanel if you're using Text Animator), they automatically send the "Typed" sequencer message. You don't need a custom script to send "TypeEnds", and you don't need to set anything in the typewriter's OnEnd() event.

The actual text "GiveItem(item)" in my previous reply was just a hypothetical example that assumes you've written a custom sequencer command named GiveItem.

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Mon Feb 13, 2023 2:22 pm
by laurelhach
Yes I did :) Sorry I didn't put the code.
And I use "TextMeshProTypewriterEffect", but I didn't receive the message "Typed".

Code: Select all

    public class SequencerCommandGiveItem : SequencerCommand
    { 

        public void Awake()
        {
            string itemName = GetParameter(0);
            QuestManager.Instance.GiveItemFromConversation(itemName);
            Stop();
          }
     }


Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Mon Feb 13, 2023 2:56 pm
by Tony Li
Here's an example scene:

DS_TypedExample_2023-02-13.unitypackage

It uses a ShowAlert()@Message(Typed) sequencer command instead of a custom sequencer command, but that shouldn't matter; it still demonstrates the use of @Message(Typed).

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Tue Feb 14, 2023 1:51 pm
by laurelhach
Hi Tony,

So after investigation, the problem is when I press the continue button, the custom command is not triggered, but your internal command is (ShowAlert()).
If I wait the end of the dialogue (typewriting is done) then my custom command is executed.

Not sure if this is intentional ? or is there something I'm missing ?
btw I was using your template, I've just added a custom command script to test it.

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Tue Feb 14, 2023 3:46 pm
by Tony Li
Hi,

It's intentional. Put the keyword 'required' in front of the command to require it to run even if the player skips ahead using the continue button. (The ShowAlert() command just happens to work in this case due to a different reason: when a conversation ends, it checks if an alert message is pending in the "Alert" variable.)

Code: Select all

required GiveItem(item)@Message(TypeEnds)

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Tue Feb 14, 2023 5:44 pm
by laurelhach
Thank you :)

Just out of curiosity, was that information in the doc section ? maybe I didn't pay attention, but I haven't seen it.
At least it works now.

Re: Trigger Script (or Else) at the end of a conversation node (dialogue entry)

Posted: Tue Feb 14, 2023 6:44 pm
by Tony Li
Glad to help!

Technically it's there under Sequencer Command Syntax, but the Dialogue System has a lot of documentation so it's easy to miss little things like this.