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 /
avatar image
0
Question by meaningoflife42 · Jul 29, 2014 at 04:01 AM · javascriptbugtext

Text clearing issue- game breaking

Once again, I must turn to the community for help. I am creating a text adventure, and am encountering a severe problem. Code:

  #pragma strict
     //Keywords and keyword bools.
     private var examineWords= ["examine", "Examine","examine room","Examine room","check room","Check room", "look" ,"Look","Look around","Look around","Inspect","inspect","inspect room", "Inspect room"];
     private var exitWords= ["exit","Exit","leave","Leave","Exit room","exit room","Leave room","leave room","open door","Open door"];
     private var keyWords=["get key","Get key","Pick up key", "pick up key","Grab key","grab key","Grab","grab","take key","Take key"];
     private var isExamineOnList : boolean=false;
     private var isExitOnList : boolean=false;
     private var isKeyOnList : boolean=false;
     //Text box bools.
     private var showBox1 : boolean = true;
     private var showExamine1 : boolean=false; 
     private var showBox2 : boolean=false;
     private var showExamine2 : boolean=false;
     private var showKey2 : boolean=false;
     //Misc.
     var arcadeText : GUIStyle;
     var stringToEdit : String = "";
     
     
         function OnGUI (){
         //Return functionality.
             var returnHit = (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return);
             stringToEdit = GUI.TextField (Rect (19, 397, 600, 20), stringToEdit, 240, arcadeText);
         
              if(returnHit) {
     Return();
     
         
         }
         //Light room desc 1.
         if (showBox1 == true)
         
        {GUI.Box(Rect(0,0,Screen.width,Screen.height),"Greetings, Adventurer. You have but one goal: to return to reality.\nYou are in a low-lit stone room with a single unlocked door visible.", arcadeText);}
       //Light room desc 2.
       if (showBox2== true)
       
         {GUI.Box(Rect(0,0,Screen.width,Screen.height),"The next room you enter is an intersection, with one path branching forward and\none right, with a locked door blocking each. To the left hangs a rusted but still\nfunctional key on a chain. As soon as you enter, the door behind you slams shut,\nfusing itself to the wall. You must press on. You see footprints matching yours\non the floor. Have you done this before?", arcadeText);}
       //for statements
       for each (var word1 in examineWords){if (word1==stringToEdit){isExamineOnList=true;}
       }
       
       for each (var word2 in exitWords) {if (word2==stringToEdit){isExitOnList=true;} 
             }
       for each (var word3 in keyWords) {if (word3==stringToEdit){isKeyOnList=true;}
       }
       
         //Box 1 ifs.     
         if (isExamineOnList==true && returnHit && showBox1==true) {showBox1=false; showExamine1=true;}      
         if (showExamine1==true){GUI.Box(Rect(0,0,Screen.width,Screen.height),"Upon further inpection, the craftmanship looks ancient, with moss growing in\nsome places. Dripping water and cool air suggests a deep climate, and the light\nhas no visible source.", arcadeText); ExamineBox1();}    
         if (isExitOnList==true && returnHit && showBox1==true) {showBox1=false; BoxWait();}
         //Box 2 ifs.
         if (isExamineOnList==true && returnHit && showBox2==true) {showBox2=false; showExamine2=true;}  
         if (showExamine2==true) {GUI.Box(Rect(0,0,Screen.width,Screen.height),"This room is nearly identical to the last. The rusted key appears to be in\nworking order. There is no trace of the previous room, and the door appears as\nhard as the surrounding stone. The footprints are indeed a perfect match to\nyour own. Each corridor is locked firmly. Perhaps the key could do the trick...  ", arcadeText); ExamineBox2();}    
         if (isKeyOnList==true && returnHit && showBox2==true) {showBox2=false; showKey2=true;}
         if (showKey2==true) {GUI.Box(Rect(0,0,Screen.width,Screen.height),"Key acquired. Try using it!", arcadeText); KeyBox2();}
     }
     function Return () { stringToEdit = stringToEdit; yield WaitForEndOfFrame; stringToEdit= "";} 
     function BoxWait(){yield WaitForSeconds(1.0); showBox2=true;}
     function ExamineBox1(){
     yield WaitForSeconds(9.0); isExamineOnList=false; showExamine1=false; showBox1=true;} 
     function ExamineBox2(){
     yield WaitForSeconds(9.0); isExamineOnList=false; showExamine2=false; showBox2=true;} 
     function KeyBox2(){
     yield WaitForSeconds(3.0); showKey2=false; showBox2=true; } 

I apologize for including all of my code but I have no idea what is wrong. The basis of what this is is that a for function detects if the typed phrase is on a list of keywords, and depending on the area, certain text boxes are put into use. However, particularly after typing an "examine" keyword, it will execute perfectly. The next code, however will not clear the previous text box, making 2 on the screen at once. The next detected phrase that is on the list will only clear the previous phrase, and then the game will function as normal. If the isExamineOnList of the bottom functions is removed, then the next text box will not even appear, going back to whatever the examine function was. From then on in that case, all keywords will lead to examine. Pictures of text box meshing:alt text (caused by examine and then exit, both text boxes with original room descriptions active) alt text (mesh of get key text and normal box2 text performed after examine. This did resolve itself after the get key had 3 seconds pass).

This is a very weird bug and I would appreciate any help you could give.

EDIT: sorry for not formatting all of the text to code- resolved.

screen shot 2014-07-28 at 6.47.10 pm.png (11.5 kB)
screen shot 2014-07-28 at 6.43.04 pm.png (15.2 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by meaningoflife42 · Jul 30, 2014 at 01:27 AM

Fixed it myself and posting in case anyone else has this issue- made a variable(boolean) named stringSafety that would allow the normal text field if true and would disable it if it was false. Then, I just added it in to all the cofunctions. I found that for some reason, it would redo the original seconds that the examine and key text boxes would stay on screen and in that period, any inputs would cause odd effects like duplication of text boxes shown above. Therefore, I just would turn stringSafety to false during the problem period and then back to true at the end, allowing input. In addition, I found that my code would not reset, A.K.A. that if I typed in an exit keyword then deleted that and typed in an examine keyword, the exit keyword would take preference due to never being disabled. Therefore, I wrote that if the string was blank, all booleans for the is___OnList would be disabled. Code used:

   var stringSafety : boolean=true;
         
                 if (stringSafety==true){stringToEdit=GUI.TextField (Rect (19, 397, 600, 20), stringToEdit, 240, arcadeText);}
             
                     if (stringSafety==false) {GUI.Box (Rect (19, 397, 600, 20), "CALCULATING...PLEASE WAIT", arcadeText);}
                     if (stringToEdit=="") {isExamineOnList=false; isExitOnList=false; isKeyOnList=false;}
             
             Examine/Exit/Key functions edited:
             
                 function ExamineBox1(){yield WaitForSeconds(8.0); isExamineOnList=false; showExamine1=false; showBox1=true; stringSafety=false; yield WaitForSeconds(8.0); stringSafety=true;} 
                 function ExamineBox2(){
                 yield WaitForSeconds(8.0); isExamineOnList=false; showExamine2=false; showBox2=true;stringSafety=false;yield WaitForSeconds(8.0); stringSafety=true;} 
                 function KeyBox2(){
                 yield WaitForSeconds(3.0);isKeyOnList=false; showKey2=false; showBox2=true; stringSafety=false; yield WaitForSeconds(3.0); stringSafety=true;} 
 

Hope this helps the small minority that have my exact problem!

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Unity 4.6 Text Misbehaves During Gameplay 1 Answer

unity bug??? while loop is satisfied, but doesn't quit 2 Answers

Keyboard Cursor Delay Issue 0 Answers

semicolon expected while semicolon is present 1 Answer

Try to reproduce this Text UI element "bug" if you are developing for IOS 0 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