Getting Speaker&Listener from Script uses previous node's values

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Jamez0r
Posts: 61
Joined: Fri Nov 20, 2020 8:18 pm

Getting Speaker&Listener from Script uses previous node's values

Post by Jamez0r »

Hi Tony :D

I've been using the Dialogue System for years, so I'm familiar with most things, but running into a new issue that is only popping up because the new project I'm working on has 'conversations' that take place between two NPCs (and not just between the NPC and the "player").

The issue seems to be the same thing this person had, where if you are checking who the Speaker & Listener are via a "Script" field command, you get the Speaker & Listener from the previous node: https://www.pixelcrushers.com/phpbb/vie ... hp?p=37361

In my case, I'm using the Script field to send a command to our FSM to make the appropriate character do an animation, so I need to know which NPC is the Speaker and which is the Conversant for each particular node:
script command.png
script command.png (179.83 KiB) Viewed 2183 times
How can I get the actual Speaker & Listener for the node that the "Script" command is being processed from? I'm a bit confused as to why the Speaker/Listener wouldn't already have been updated to the new node's values when the "Script" commands are being executed. The fact that it isn't updated at that point makes me think that the "Script" commands might not be intended to be used in this way (to apply an animation to the Speaker/Listener for the current node). If that's the case, what would be the recommended way to do it? I could potentially make a custom Sequence command for triggering animations on our NPCs if that is more of the intended way... but in our situation these animation-triggers aren't meant to be used in any sort of actual 'sequence', they should just get fired off immediately when the conversation reaches that node, so thats why we are simply using "Script" commands.

Thanks for any help!!

Edit: Just wanted to add that I'm on version 2.2.39, a pretty old version, in case any changes to this has been made since then - I scanned through the patch notes and didn't notice anything related to it.
User avatar
Tony Li
Posts: 23254
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting Speaker&Listener from Script uses previous node's values

Post by Tony Li »

Hi,

The short answer is to use the sequencer command version of FSMEvent().

This is a case where there's no "perfect" solution.

The Dialogue System runs the Script field before setting up the ConversationState because commands in the Script field may change variables that the Dialogue Text references. For example:

scriptBeforeState.png
scriptBeforeState.png (37.91 KiB) Viewed 2077 times

In this case, the script must run before the Dialogue System processes Dialogue Text and creates the ConversationState.

However, the downside (as you've seen) is that the Script field can't use DialogueManager.currentConversationState. The two common solutions for this are to:
  • Use sequencer commands, which run after the ConversationState has been created, or
  • Record the dialogue entry in an OnPrepareConversationLine(DialogueEntry) method. The Dialogue System calls method before running the script, as part of preparing to create the ConversationState.
Jamez0r
Posts: 61
Joined: Fri Nov 20, 2020 8:18 pm

Re: Getting Speaker&Listener from Script uses previous node's values

Post by Jamez0r »

Thank you for the in-depth explanation. That all makes sense, and from the looks of it we should be using the Sequencer for this type of thing anyway, so we'll switch over to using it. Appreciate the help as always!
User avatar
Tony Li
Posts: 23254
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting Speaker&Listener from Script uses previous node's values

Post by Tony Li »

Glad to help!
Post Reply