- Home /
Why are some of my methods being skipped?
I am creating a dialogue system that continues the dialog every time a key is pressed. However, when it comes to dialogue that involves choices, only the first choice dialogue plays. Both choice dialogue and non-choice dialogue use the same method, ReadLine(), but choice dialogue includes a number that prevents the dialogue from playing unless it matches the number determined by the choices. There are no differences in the conditions for the choice dialogue, so I do not know what is missing that allows it to be skipped. Thanks in advance for the help. Here is what I currently have:
Dialogue Script:
//Play dialogue:
void Update()
{
ToggleDialogueBox();
ReadLine("David", "This is a test.");
ReadLine("Alfred", "Did it work?");
ReadLine(null, "Did the text type out like a typewriter?");
AskQuestion(null, "What do you think?");
ReadLine("You", "Yes.", 1);
ReadLine("David", "We agree.", 1);
ReadLine(null, "Goodbye.");
ToggleDialogueBox();
}
//Type dialogue:
void ReadLine(string name, string text)
{
TypeDialogue(name, text);
if ((textBox.text == text || nameBox.text == text) && dialogueScript.Count > textIndex && Input.GetKeyDown(KeyCode.T))
{
textIndex++;
}
}
//Type dialogue for choices (overload):
void ReadLine(string name, string text, int num)
{
if (num == choiceNum)
{
TypeDialogue(name, text);
}
if ((textBox.text == text || nameBox.text == text) && dialogueScript.Count > textIndex && Input.GetKeyDown(KeyCode.T))
{
textIndex++;
}
}
//Get choices:
void AskQuestion(string name, string text)
{
choiceNum = 0;
TypeDialogue(name, text);
if ((textBox.text == text || nameBox.text == text) && dialogueScript.Count > textIndex)
{
if (Input.GetKeyDown(KeyCode.O))
{
choiceNum = 1;
textIndex++;
}
if (Input.GetKeyDown(KeyCode.P))
{
choiceNum = 2;
textIndex++;
}
}
}
//Function for conversation:
void TypeDialogue(string name, string text)
{
if (dialogueScript.Count == textIndex && dialogueBox.gameObject.activeSelf)
{
string[] line = { name, text };
if (!dialogueScript.Contains(line))
{
dialogueScript.Add(line);
}
if (dialogueScript[textIndex][0] == null)
{
nameBox.text = string.Empty;
}
else
{
nameBox.text = name;
}
textBox.text = string.Empty;
StartCoroutine(TypeLine(dialogueScript[textIndex][0], dialogueScript[textIndex][1]));
}
}
}
No ones is going to read 140 lines to try and fix your problem when you can fix it yourself with a breakpoint. https://docs.unity3d.com/Manual/ManagedCodeDebugging.html
I wouldn't have submitted my issue to Unity Answers if I could get the debugger to work. I removed some things. Is that short enough?