Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 15, 2013 at 08:46 AM by Fattie for the following reason:

Question is off-topic or not relevant - nothing to do with Unity. try stackoverflow

avatar image
1
Question by Hyperion · Oct 15, 2013 at 02:22 AM · aiboolbooleans

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

Comment
Add comment · Show 15
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image harko12 · Oct 15, 2013 at 02:25 AM 0
Share

So.. don't set the flag until after the answer is displayed the first time?

avatar image Hyperion · Oct 15, 2013 at 02:26 AM 0
Share

Basically, yes.

avatar image harko12 · Oct 15, 2013 at 02:39 AM 1
Share

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

avatar image DylanW · Oct 15, 2013 at 02:43 AM 0
Share

harko12's answer is pretty straight forward. Just simply set the flag to false after you provide the answer.

avatar image harko12 · Oct 15, 2013 at 03:14 AM 1
Share

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.

Show more comments

1 Reply

  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hyperion · Oct 15, 2013 at 04:03 AM 0
Share

So if you press 1, then 2, then 1 again, it will not display 1, correct?

avatar image DylanW · Oct 15, 2013 at 06:26 PM 0
Share

Yes that is right.

avatar image Hyperion · Oct 16, 2013 at 12:11 AM 0
Share

Thank you for your help.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scavenger Hunt List Bools Question 1 Answer

Simple controller is not so simple,Trying to animate with Bools 1 Answer

Need help with enemy script (C#)(2D) 0 Answers

Can you use triggers in script? 2 Answers

How can i reverse all the booleans in a method? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges