Calling dialogues and controlling paths from script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Jesse
Posts: 8
Joined: Sun Jun 02, 2019 8:03 am

Calling dialogues and controlling paths from script

Post by Jesse »

Hello Tony,

I hope you are doing well! I have a question or two if you don't mind.

I tried looking through the documentation and some threads. This thread looked pretty close:
Start Conversation by ID

I have a system to call dialogues already and it's mostly setup but now I would like to switch to your brilliant and well optimized Pixel Crusher dialogue system in for my previous system dialogue system (+8,000 line custom code gone *SOBS*).

string Dialogue1 = "Name of dialogue to call1"
string Dialogue2 = "Name of dialogue to call2"
string Dialogue3 = "Name of dialogue to call3"
string Dialogue4 = "Name of dialogue to call4"
string Dialogue5 = "Name of dialogue to call5"
string Dialogue6 = "Name of dialogue to call6"
string Dialogue7 = "Name of dialogue to call7"
string Dialogue8 = "Name of dialogue to call8"
string Dialogue9 = "Name of dialogue to call9"

string Victory = "Name of dialogue to callV"
string VictoryPost = "Name of dialogue to callVP"
string Defeat = "Name of dialogue to callD"
string DefeatPost = "Name of dialogue to callDP"

(most characters don't utilize all of the dialogue slots, most just use either 1 or 4, but some use all of them. For the characters that have only 1 dialogue I am moving over to your bark dialogue system, almost ready to implement.)

THE SMART WAY (if possible)
Now I know that is lot of variables to have dialogues saved in here as strings. I saw the system where you have a group passthrough and then control which dialogue path has priority. That seems very intelligent and well designed but I don't know how to control which dialogue/path in there has priority. It looks like you're supposed to use the conditions system or quest system but I don't think I will use that because we already have both of those systems setup and filled with content.
For example Starter Group that is passthrough to 3 dialogues
-Dialogue - Ask to battle - PATH 1
-Dialogue - Player Wins - PATH 2
-Dialogue - Player Loses and npc asks for a rematch - PATH 3

Question:
Is there a way to control the path for the dialogue through code. If I could say "Path 2 will have priority". If there was an easy way to call the Path Number that would be excellent. How do I set that in both C# and Unityscript? (I'm in Unity 5.6)

THE ALREADY SETUP WAY
I already have a system to save, store, and advance the dialogues. But I don't know how to call them by string name

This bit of code right here is super helpful but I don't know how to call the conversation/make it fire.
var title = DialogueManager.MasterDatabase.GetConversation(id).Title;
var id = DialogueManager.MasterDatabase.GetConversation("title").id;

Question:
So in the variables above. How do I call the dialogue by title (string)? Or if I can't call dialogues by title, how do I call them by ID (ints)? How do I call in both C# and Unityscript?

I would be grateful for any help. Thank you!

Warm Regards,
Jesse
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling dialogues and controlling paths from script

Post by Tony Li »

Hi Jesse,
Jesse wrote: Tue Jun 25, 2019 3:37 pmQuestion:
Is there a way to control the path for the dialogue through code. If I could say "Path 2 will have priority". If there was an easy way to call the Path Number that would be excellent. How do I set that in both C# and Unityscript? (I'm in Unity 5.6)
I recommend using Conditions instead of Priority. Assign the same priority (Normal) to all path links.

Add a Dialogue System variable in the Variables section of the Dialogue Editor. Let's say that variable is named "Path" and its Type is Number.

On the first path, set the Conditions field to:

Code: Select all

Variable["Path"] == 1
On the second:

Code: Select all

Variable["Path"] == 2
etc.

You can use the "..." tool to specify these conditions. You don't have to type them manually.

Before starting your conversation, set "Path" to the path that you want to use. Then start the conversation. C# example:

Code: Select all

using PixelCrushers.DialogueSystem;
...
DialogueLua.SetVariable("Path", 2);  // Player wins.
DialogueManager.StartConversation("Your Conversation");
You can use the same methods in UnityScript. Although I recommend using C# since UnityScript has since been removed from Unity.

Alternatively, you can set up a DialogueSystemTrigger component. Set it to OnUse, and select Add Action > Start Conversation. You can trigger it with a UnityEvent or Select, or you can trigger it in code, such as:

Code: Select all

GetComponent<DialogueSystemTrigger>().OnUse();
Jesse
Posts: 8
Joined: Sun Jun 02, 2019 8:03 am

Re: Calling dialogues and controlling paths from script

Post by Jesse »

Tony, you are a genius. This is so much better than what I thought possible! I am going to start working with this now. Thank you so very much!
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling dialogues and controlling paths from script

Post by Tony Li »

Happy to help!
Jesse
Posts: 8
Joined: Sun Jun 02, 2019 8:03 am

Re: Calling dialogues and controlling paths from script

Post by Jesse »

Hello Tony,

I hope you are well! Your previous reply was extremely helpful! Thank you so so much!

I have some more questions if you don't mind. I would like to fire a sequence event at the end of the dialogue. Right now, the sequence fires at the beginning of that dialogue screen.

For example. The player accepts the battle request from someone in dialogue and then it loads the battle screen and battle level. But right now it loads the battle screen and battle level while the dialogue is still open. I would like the dialogue to be closed when I open up the other stuff.

1st Question
How do I tell a sequence to fire at the end of a dialogue screen? or for a sequence to fire and then close the dialogue.

2nd Question
Through script how do I cancel the current dialogue?
Something like:

Code: Select all

DialogueManager.CancelConversation
would be amazing. If this does exist then please forgive me, I tried looking it up on the dialogue API site but I am having trouble locating it.
http://www.pixelcrushers.com/dialogue_s ... Attributes

3rd Question (sorry there are so many)
Something slightly unrelated. How do I tell a bark dialogue to fire? and can I use the variable path system that you showed me previously but with barks too?

Would this work for barks?

Code: Select all

using PixelCrushers.DialogueSystem;
...
DialogueLua.SetVariable("Path", 2);  // Set correct bark path
GetComponent<DialogueSystemTrigger>().OnUse(); //This line activates the bark dialogue and makes the bubble appear above their head with dialogue
4th Question (sorry there are so many)
Something slightly unrelated. Is there a global enumerator variable that will state if the dialogue system is playing a dialogue? If there is then I was going to hook up the player's movement based on if there is a dialogue actively playing. (If dialogue is playing then player can't move).

Code: Select all

//Something like this
DialogueEngine.PlayingDialogue
DialogueEngine.NoDialogueActive
//where "DialogueEngine" is the enum and "PlayingDialogue" is the state of the enum. If this doesn't exist then it is okay. Just trying to show what I am talking about because words are hard
I would be grateful for any help. Sorry for asking so many questions. I completely understand if it takes some time to respond. I know answering these questions is very time-consuming. Thank you so much and sorry to keep bothering you!

Have a wonderful day!

Warm Regards,
Jesse
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling dialogues and controlling paths from script

Post by Tony Li »

Hi Jesse,
Jesse wrote: Sun Jun 30, 2019 4:41 pmHow do I tell a sequence to fire at the end of a dialogue screen? or for a sequence to fire and then close the dialogue.
(I'm assuming an NPC in this answer, but the answer is similar even if you don't specifically have an NPC.)

In the conversation, set a Dialogue System variable true so you know whether the player accepted the battle during the conversation. For example, let's say the variable is named "acceptedBattle".

Add a Dialogue System Trigger to the NPC.
  • Set its trigger dropdown to On Conversation End.
  • In the Condition section, require that the variable "acceptedBattle" is true. You can do this using the Lua Conditions section's "..." dropdown menus or manually typing it:

    Code: Select all

    Variable["acceptedBattle"] == true
  • In the Actions section, select Add Action > Play Sequence. Enter your sequence.
Jesse wrote: Sun Jun 30, 2019 4:41 pmThrough script how do I cancel the current dialogue?
Use DialogueManager.StopConversation():

Code: Select all

DialogueManager.StopConversation();
Jesse wrote: Sun Jun 30, 2019 4:41 pmSomething slightly unrelated. How do I tell a bark dialogue to fire? and can I use the variable path system that you showed me previously but with barks too?
Yes, you can use variables in your bark triggers. If you've set up a Dialogue System Trigger to bark then, yes, your code is perfect. You can also call DialogueSystem.Bark() or DialogueManager.BarkString() manually in code if you want.
Jesse wrote: Sun Jun 30, 2019 4:41 pmSomething slightly unrelated. Is there a global enumerator variable that will state if the dialogue system is playing a dialogue? If there is then I was going to hook up the player's movement based on if there is a dialogue actively playing. (If dialogue is playing then player can't move).
Yes. DialogueManager.isConversationActive. However, rather than polling it, you may want to add a Dialogue System Events component to your player and configure the OnConversationStart() and OnConversationEnd() events to disable and re-enable your player's movement components. (The second half of the Interaction Tutorial covers this, too, if you want a step-by-step with commentary.) Or you can add the Special Script Methods OnConversationStart(Transform) and OnConversationEnd(Transform) to your player's script(s). In OnConversationStart, turn off movement. In OnConversationEnd, turn it back on.

I'm always happy to answer questions, so if any more come up, please ask away!
Jesse
Posts: 8
Joined: Sun Jun 02, 2019 8:03 am

Re: Calling dialogues and controlling paths from script

Post by Jesse »

This is perfect! Thank you so very much, Tony! I really appreciate you taking time to answer these questions. Have a wonderful day!
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling dialogues and controlling paths from script

Post by Tony Li »

Happy to help!
Post Reply