Choose the conversation by the condition.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jagermeister35
Posts: 6
Joined: Thu Jul 16, 2015 9:32 am

Choose the conversation by the condition.

Post by jagermeister35 »

Hi there
We are creating the game, which is almost entirely built on dialogue and quests.
Your system is fantastic and gives us many opportunities to do so.
But there is a problem: all conversations in dialogue must depend on each other, so it is necessary to set certain conditions start some conversation, depending on how the previous was ended.
Is there some way to define what Dialogue Entry id was the last chosen
(or was evere chosen)?
To set something like this:
if(TheLastDialogueEntreID==2){
DialogueSystem.StartConversation("Conversation 1")
}
Or maybe there are other methods to do this. Thank you!
User avatar
Tony Li
Posts: 22102
Joined: Thu Jul 18, 2013 1:27 pm

Re: Choose the conversation by the condition.

Post by Tony Li »

Hello,

There are many ways you can do this. I recommend using Lua variables in the dialogue database. They make the intention much clearer than using "magic numbers" like TheLastDialogueEntryID==2.

For example, say you have a Conversation titled "The Choice". In this conversation, the player can choose the red pill or the blue pill. In your dialogue database, add a variable named Pill. In the dialogue entry "I choose the red pill", use the Script field to set Variable["Pill"] = "red". In the dialogue entry "I choose the blue pill", use the Script field to set Variable["Pill"] = "blue".

Later, in a script you can check the variable's value:

Code: Select all

if (DialogueLua.GetVariable("Pill").AsString == "red") {
    DialogueManager.StartConversation("Red Pill Conversation");
} else {
    DialogueManager.StartConversation("Blue Pill Conversation");
}
Or you can add two Conversation Triggers. Set the Condition of one trigger to Variable["Pill"] == "red". Set the Condition of the other trigger to Variable["Pill"] == "blue".


Here are some alternatives:
  • On the Dialogue Manager, tick Use SimStatus. Then you can check Conversation[#].Dialog[#].SimStatus, which will be a string "Untouched", "WasOffered", or "WasDisplayed". "WasDisplayed" means the conversation played the dialogue entry. Note that this option requires more memory because it has to record the SimStatus of each dialogue entry.
  • Add a script to the Dialogue Manager that has an OnConversationLine method:

Code: Select all

void OnConversationLine(Subtitle subtitle) {
    TheLastDialogueEntryID = subtitle.dialogueEntry.id;
}
jagermeister35
Posts: 6
Joined: Thu Jul 16, 2015 9:32 am

Re: Choose the conversation by the condition.

Post by jagermeister35 »

Thank you a lot! It`s very helpfull.
jagermeister35
Posts: 6
Joined: Thu Jul 16, 2015 9:32 am

Re: Choose the conversation by the condition.

Post by jagermeister35 »

One more question, I need to change the variable "Score" from code to make condition for success ending of my quest.
I have an error:
Dialogue System: Lua code 'return (Variable["Score"] < 3) and (Quest["ITEMS"].State == "active")' threw exception 'Object reference not set to an instance of an object'
UnityEngine.Debug:LogError(Object)
My code is:
if (Input.GetMouseButtonDown(0) && hit.collider != null && hit.collider.name == "sunduk" && hit.collider.name == "lightening" && hit.collider.name == "bottle")
{
int oldValue = DialogueLua.GetVariable(varible).AsInt;
int newValue = Mathf.Clamp(oldValue + increment, 0, 3);
DialogueLua.SetVariable(varible, newValue);
DialogueManager.Instance.SendMessage("UpdateTracker", SendMessageOptions.DontRequireReceiver);
// score++;
}
what does it mean?
User avatar
Tony Li
Posts: 22102
Joined: Thu Jul 18, 2013 1:27 pm

Re: Choose the conversation by the condition.

Post by Tony Li »

Hi,

Can you please post the entire stack trace for the error? In the Console view, click on the error line. Press Ctrl-C to copy it to the clipboard (Command-C on Mac). Then paste it into a reply here.

Thanks,
Tony
jagermeister35
Posts: 6
Joined: Thu Jul 16, 2015 9:32 am

Re: Choose the conversation by the condition.

Post by jagermeister35 »

That`s it.
Dialogue System: Lua code 'return (Variable["Score"] < 3) and (Quest["ITEMS"].State == "active")' threw exception 'Object reference not set to an instance of an object'
UnityEngine.Debug:LogError(Object)
PixelCrushers.DialogueSystem.Lua:RunRaw(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.Lua:Run(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.Lua:IsTrue(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinksAtPriority(ConditionPriority, DialogueEntry, List`1, List`1, List`1, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinks(DialogueEntry, List`1, List`1, List`1, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:GetState(DialogueEntry, Boolean, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:.ctor(DialogueDatabase, String, Transform, Transform, Boolean, IsDialogueEntryValidDelegate, Int32, Boolean)
PixelCrushers.DialogueSystem.DialogueSystemController:StartConversation(String, Transform, Transform, Int32)
PixelCrushers.DialogueSystem.DialogueSystemController:StartConversation(String, Transform, Transform)
PixelCrushers.DialogueSystem.DialogueManager:StartConversation(String)
quest1:Update() (at Assets/TEST/quest1.cs:22)
jagermeister35
Posts: 6
Joined: Thu Jul 16, 2015 9:32 am

Re: Choose the conversation by the condition.

Post by jagermeister35 »

Hi tony! I made some modification on settings, so now i havn`t that error, but counter doesn`t work anyway . I am writing my code by this example https://www.youtube.com/watch?v=JMlSyDG ... e=youtu.be .
this is my condition:

if (!string.IsNullOrEmpty(varible) && Input.GetMouseButtonDown(0) && hit.collider != null && (hit.collider.name == "chest" || hit.collider.name == "candle" || hit.collider.name == "bottle"))
{
int oldValue = DialogueLua.GetVariable(varible).AsInt;
int newValue = Mathf.Clamp(oldValue + increment, min, max);
DialogueLua.SetVariable(varible, newValue);
DialogueManager.Instance.SendMessage("UpdateTracker", SendMessageOptions.DontRequireReceiver);
}
Thank you!
User avatar
Tony Li
Posts: 22102
Joined: Thu Jul 18, 2013 1:27 pm

Re: Choose the conversation by the condition.

Post by Tony Li »

Hi,

Can you put some Debug.Log lines in the code to make sure it's called?

For example:

Code: Select all

if (!string.IsNullOrEmpty(varible) && Input.GetMouseButtonDown(0) && hit.collider != null && 
    (hit.collider.name == "chest" || hit.collider.name == "candle" || hit.collider.name == "bottle"))
{
    int oldValue = DialogueLua.GetVariable(varible).AsInt;
    int newValue = Mathf.Clamp(oldValue + increment, min, max);
    DialogueLua.SetVariable(varible, newValue);
    Debug.Log("<color=cyan>NEW VARIABLE '" + varible + "' VALUE = " + newValue + " </color>"); //<-- ADD THIS.
    DialogueManager.Instance.SendMessage("UpdateTracker", SendMessageOptions.DontRequireReceiver);
}
Also, if your quest tracker is on a child GameObject, use BroadcastMessage:

Code: Select all

DialogueManager.Instance.BroadcastMessage("UpdateTracker", SendMessageOptions.DontRequireReceiver);
or just call DialogueManager.SendUpdateTracker:

Code: Select all

DialogueManager.SendUpdateTracker();
Post Reply