- Home /
Question is off-topic or not relevant - nothing to do with Unity. try stackoverflow
An Orderly Boolean Conversation
Hello Everyone,
I have an AI responding to me when I type something in, which works without error. Except I can type the same thing in any number of times, and it will respond the same thing all those times (which I do not want). Therefore, I want it to recognize when a question has been asked.
I made a variable "saidHello=false" and required the AI to answer only if saidHello is false. Once I've typed in 'hello', saidHello should become true. PROBLEM: when saidHello becomes true, the AI does not display the answer anymore! I want it not to display the same answer only after it's been asked once, not once it's been asked once. I've been struggling to find a solution to this.
I appreciate your help.
Hyperion
So.. don't set the flag until after the answer is displayed the first time?
So what you want to do is wait in your code until after you get your answer, then set your flag. Without seeing some code that's about all I can tell you
harko12's answer is pretty straight forward. Just simply set the flag to false after you provide the answer.
well I'm going to bed so this will have to be my last word on it for now, but if you are having this much trouble, you may want to reconsider how you are doing things. the GUI stuff is good for displaying, but not much for feedback besides button clicking that I've messed with. Have you considered a button to 'answer' the question, that way you can increment on click? Or have the decisions about what to show happen in another function, and just set a string for the GUI to display? Anyway, good luck, I'll see how it turned out tomorrow.
Answer by DylanW · Oct 15, 2013 at 03:49 AM
So I have provided a script. This script will display certain texts based on the keys that are pressed. Its basically the same as what you are trying to do. However, this script prevents the system from displaying the same message.
var answeredQuestion1 : boolean = false;
var answeredQuestion2 : boolean = false;
var answeredQuestion3 : boolean = false;
var questionNumber : int = 0;
var questionAnswer : String;
function OnGUI()
{
switch(true)
{
case questionNumber == 1 && !answeredQuestion1:
// Prevents the AI from answering the same old question.
answeredQuestion1 = true;
Debug.Log("Q1");
break;
case questionNumber == 2 && !answeredQuestion2:
answeredQuestion2 = true;
Debug.Log("Q2");
break;
case questionNumber == 3 && !answeredQuestion3:
answeredQuestion3 = true;
Debug.Log("Q3");
break;
}
// Displays the answer.
GUI.Label(Rect(100, 100, 100, 100), questionAnswer);
}
function Update()
{
// Instead of typing something in, you have to press a key.
if(Input.GetKeyDown("1")) {
// The question flag.
questionNumber = 1;
// The answer.
questionAnswer = "Question 1 answered.";
}
else if(Input.GetKeyDown("2")) {
questionNumber = 2;
questionAnswer = "Question 2 answered.";
}
else if(Input.GetKeyDown("3")) {
questionNumber = 3;
questionAnswer = "Question 3 answered.";
}
};
So if I pressed the number 1 key, it will display "Question 1 answered." once.
So if you press 1, then 2, then 1 again, it will not display 1, correct?