Page 1 of 1

Choose the conversation by the condition.

Posted: Wed Jul 29, 2015 3:40 am
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!

Re: Choose the conversation by the condition.

Posted: Wed Jul 29, 2015 10:09 am
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;
}

Re: Choose the conversation by the condition.

Posted: Tue Aug 04, 2015 4:52 am
by jagermeister35
Thank you a lot! It`s very helpfull.

Re: Choose the conversation by the condition.

Posted: Fri Aug 07, 2015 8:46 am
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?

Re: Choose the conversation by the condition.

Posted: Fri Aug 07, 2015 10:25 am
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

Re: Choose the conversation by the condition.

Posted: Thu Aug 13, 2015 4:31 am
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)

Re: Choose the conversation by the condition.

Posted: Thu Aug 13, 2015 6:04 am
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!

Re: Choose the conversation by the condition.

Posted: Thu Aug 13, 2015 9:15 am
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();