Make a conversation advance based on the status of a second one

Announcements, support questions, and discussion for the Dialogue System.
Error412
Posts: 23
Joined: Sat Feb 05, 2022 4:52 am

Make a conversation advance based on the status of a second one

Post by Error412 »

Hi, I have 2 conversations running at the same time and always active.
I would like the two to interact, for example the 1st to stop until further progress has been made within the 2nd one.
I tried to use a variable, set by a node in the 2nd conversation and then checked by the 1st conversation which works quite well.
Unfortunately if the 1st conversation have reached the node where the variable is tested, before being set by the 2nd, the conversation get stuck as the test in executed only once.
I tried then sending a sequence message which have the opposite downside: it works perfectly if the user reach the node before triggering the SendMessage, but it's useless if the user haven't yet reached it as the message is sent only once.

I tried to solve this by creating double path: the message in conversation 2 both set a variable and send a message. Within the 1st conversation I first check for the variable. If true I move forward, if false I move to a different node that waits for the message.

I have two questions:
- Does my solution makes sense or did I create something convoluted that actually can be solved in a simpler way? :?
- If the above is optimal then I need help to understand why sending a message from one dialogue to another doesn't seem to work. I used the following syntax and none of them did work:
SendMessage(MyMessage,)
SendMessage(MyMessage, ,everyone)
SendMessage(MyMessage, ,everyone,broadcast)

Just for testing I tried to send the same message through a click on an unrelated object using a Playmaker action (SendSequencerMessage.cs) and it works perfectly somehow.
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make a conversation advance based on the status of a second one

Post by Tony Li »

Hi,

I think sequences, rather than variables, are the approach to take with this.

Scripting
If you're comfortable with a little scripting, you can write two custom sequencer commands -- for example, called something like SendSignal() and WaitForSignal(). The idea is that they'd work like WaitForMessage() except it can remember if a signal has already been sent before the conversation gets to WaitForSignal().

Conversation 1 can use WaitForSignal() to wait for a signal to be set, finishing instantly if the signal has already been set.

Conversation 2 can use SendSignal() to set the signal.

This will cover both scenarios:

Scenario 1: Conversation 1 gets to WaitForSignal() before conversation 2. Then conversation 2 uses SendSignal(), at which point conversation 1 continues.

Scenario 2: Conversation 2 uses SendSignal() before conversation 1 gets to the waiting node. When conversation 1 gets to the waiting node, WaitForSignal() sees that the signal has been set, so it continues.


Non-Scripting
If you're not comfortable with scripting, let me know. We can come up with a similar solution using PlayMaker, or it might just be easier if I were to provide the code for those two sequencer commands.
Error412
Posts: 23
Joined: Sat Feb 05, 2022 4:52 am

Re: Make a conversation advance based on the status of a second one

Post by Error412 »

Hi Tony, your suggestion makes sense but I'm not comfortable scripting, this is why I rather use Playmaker whenever possible.
If you can provide the script that would work, but I don't want to waste your time. Any idea why if I send a sequence message from one conversation it doesn't get received by the other? Perhaps if I can solve that I can just use my weird hack above :D
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make a conversation advance based on the status of a second one

Post by Tony Li »

Hi,

I think it's cleaner to use a custom sequencer command. This example scene:

DS_SignalExample_2022-03-02.unitypackage

contains two sequencer commands:
  • SendSignal(signal): Sends a signal (any arbitrary string).
  • WaitForSignal(signal): Waits for a signal, or succeeds immediately if a signal has been sent before this command runs. When this command is done, it clears the signal.
Error412
Posts: 23
Joined: Sat Feb 05, 2022 4:52 am

Re: Make a conversation advance based on the status of a second one

Post by Error412 »

Thanks Tony, this works very well!
There is just one issue, which you can reproduce if you set for conversation 1 the SMS UI: the message for "waiting signal" and "signal received" get both displayed at the same time (if the signal was already sent when the node is reached).

ps. this will probably display my ignorance but how do this scripts work without being assigned to anything? Does Unity just search all .cs files in the project? :?

ps2. is there any easy way to send this signal from within Playmaker? In case I want to do the same but due to interactions outside dialogues.
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make a conversation advance based on the status of a second one

Post by Tony Li »

Hi,
Error412 wrote: Thu Mar 03, 2022 6:11 amThere is just one issue, which you can reproduce if you set for conversation 1 the SMS UI: the message for "waiting signal" and "signal received" get both displayed at the same time (if the signal was already sent when the node is reached).
Isn't that what you would want to happen? What should happen instead?
Error412 wrote: Thu Mar 03, 2022 6:11 amps. this will probably display my ignorance but how do this scripts work without being assigned to anything? Does Unity just search all .cs files in the project? :?
Essentially yes. Unity compiles all .cs files into libraries (DLL files). C# code can then check these libraries for the existence of scripts such as the new sequencer commands.
Error412 wrote: Thu Mar 03, 2022 6:11 amps2. is there any easy way to send this signal from within Playmaker? In case I want to do the same but due to interactions outside dialogues.
Use a Play Sequence action.
Error412
Posts: 23
Joined: Sat Feb 05, 2022 4:52 am

Re: Make a conversation advance based on the status of a second one

Post by Error412 »

Hi Tony,
Tony Li wrote: Thu Mar 03, 2022 8:02 am Isn't that what you would want to happen? What should happen instead?
Ideally the "waiting for signal" message is displayed only when actually waiting for signal, if (when the node is reached) the signal has already been sent the dialogue skips to the next node instead. To me your example seems to work like this, which would be perfect, but when switching to the SMS UI both messages are displayed when the signal has already been sent before.
Please note this is not pivotal, your helped already greatly and I can find a workaround so you don't have to find a solution. I was just curious to understand if it was something simple to solve :)
Tony Li wrote: Thu Mar 03, 2022 8:02 am Essentially yes. Unity compiles all .cs files into libraries (DLL files). C# code can then check these libraries for the existence of scripts such as the new sequencer commands.
Thanks this makes sense now!
Tony Li wrote: Thu Mar 03, 2022 8:02 am Use a Play Sequence action.
I'm an idiot, of course, thanks Tony.
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make a conversation advance based on the status of a second one

Post by Tony Li »

I think the issue with the SMS UI is that it keeps a log of all subtitle texts. You may need to handle it specially somehow. Perhaps you can give that node no text.
Error412
Posts: 23
Joined: Sat Feb 05, 2022 4:52 am

Re: Make a conversation advance based on the status of a second one

Post by Error412 »

I'll give it a go, thank you!
Error412
Posts: 23
Joined: Sat Feb 05, 2022 4:52 am

Re: Make a conversation advance based on the status of a second one

Post by Error412 »

Tony Li wrote: Thu Mar 03, 2022 8:02 am Use a Play Sequence action.

Hi Tony, it has been a while, I hope you are well.
I just tried this suggestion and it didn't work for me.
I have a node with a sequence set as "WaitForSignal(Test)" and within Playmaker a Start Sequence action with the sequence field as "SendSignal(Test)". I also tried to add the object contain the conversation trigger in the speaker field and check "inform partecipants" but with no result.
Post Reply