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 pulsusego · Oct 22, 2013 at 05:29 AM · javascriptscriptingproblem

Unity Javascript debug error stating BCE0044: expecting :, found ';'. Any help?

I'm sure, for what I want to accomplish, there are many problems with this script, but the one that's stopping me in my tracks right now is Unity saying there should be a colon and I've absolutely no idea how that makes any sense, and I've looked up quite a bit on the topic online to no avail. Any help would be massively appreciated, and I'll give any extra information if it's necessary. Thank you very much in advance if you can suggest anything or help at all. So, here's my script (with // annotations describing things)-

 #pragma strict
 //Main character collides with village, and 'enters' it.
 
 var visitedvillage = false;//variable stating that the character has (or has not, for false) visited the village recently. Here to make sure that after exiting the menu, the collision will not trigger again (since the character will still be colliding with the village object) until the variable is removed (by exiting contact with the object, or after a set time has passed, presumably). As of right now, you will only be able to visit the villageo once per game start, but that's not really a problem for the time being.
 
 var mediumvillagescreentoggle = false;//variable simply stating that the village menu is not currently open (false).
 
 function OnControllerColliderHit (hit : ControllerColliderHit) {
 
     if(hit.collider.gameObject.name == "Structure_Village_Medium.01") {
         if (visitedvillage == "false"){//when the main character collides, it checks if they have already visited the village recently, if they have (true) it will not fire and nothing happens, preventing an endless loop of opening the menu each time you close it once you collide with the village.
             mediumvillagescreentoggle = "true";//toggles the village menu
             if (mediumvillagescreentoggle == "true") {//not sure where else to put this besides here, though this basically jsut turns on the menus/buttons when true.
                 OnGUI(); {
                     GUI.Box(Rect(110,10,400,300),"Medium Village");//should open a box, right? but unity says BCE0044: expecting:, found ';'. I have no idea how this makes sense.. any help is greatly appreciated.
                 }
                 OnGUI(); {//added a second independent OnGUI in hopes it would help. It doesn't seem to have done anything, or hurt anything, so I haven't removed it.
                     if (GUI.Button=(Rect(120,40,180,60), "Leave Village")) {//should simply open a button that, when clicked, turns off the village menu.
                         mediumvillagescreentoggle = "false";
                     }
                 }
                 visitedvillage = "true";
                 }
             }
         }
     }
 }
Comment
Add comment · Show 1
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 yogee · Oct 22, 2013 at 05:32 AM 0
Share

line 6: error, {

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Oct 22, 2013 at 06:06 AM

You can't define OnGUI inside other functions. OnGUI is a callback function. It needs to be a member function of your script. What you've done here makes no sense at all ;)

Next thing is you can't assign a string "true" to a boolean. UnityScript is not (web)javascript, it's way different.

 function OnControllerColliderHit (hit : ControllerColliderHit) {
     if(hit.collider.gameObject.name == "Structure_Village_Medium.01") {
         if (visitedvillage == false){
             mediumvillagescreentoggle = true;
         }
     }
 }
 
 function OnGUI() {
     if (mediumvillagescreentoggle) {
         GUI.Box(Rect(110,10,400,300),"Medium Village");
         if (GUI.Button=(Rect(120,40,180,60), "Leave Village")) {
             mediumvillagescreentoggle = false;
         }
     }
 }
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
avatar image
0

Answer by OrbitSoft · Oct 22, 2013 at 06:21 AM

On line 12/19/22 you are setting BOOLEAN variables to STRING, i think this is not possible. remove the "".

Next is that you are calling OnGUI in there, i suggest you to do the following:

 #pragma strict
 //Main character collides with village, and 'enters' it.
  
 var visitedvillage = false;//variable stating that the character has (or has not, for false) visited the village recently. Here to make sure that after exiting the menu, the collision will not trigger again (since the character will still be colliding with the village object) until the variable is removed (by exiting contact with the object, or after a set time has passed, presumably). As of right now, you will only be able to visit the villageo once per game start, but that's not really a problem for the time being.
  
 var mediumvillagescreentoggle = false;//variable simply stating that the village menu is not currently open (false).
  
 function OnControllerColliderHit (hit : ControllerColliderHit) {
  
     if(hit.collider.gameObject.name == "Structure_Village_Medium.01") {
        if (visitedvillage == false){//when the main character collides, it checks if they have already visited the village recently, if they have (true) it will not fire and nothing happens, preventing an endless loop of opening the menu each time you close it once you collide with the village.
         mediumvillagescreentoggle = true;//toggles the village menu
            visitedvillage = true;
        }
     }
 }
 
 function OnGUI() {
     if (mediumvillagescreentoggle == true) {
         GUI.Box(Rect(110,10,400,300),"Medium Village");
     }
 }

I did not test the code but i hope it works.

Comment
Add comment · Show 2 · 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 pulsusego · Oct 23, 2013 at 04:37 AM 0
Share

Thank you both greatly, I haven't had the chance to work on fixing it yet (just finished my midterm for a class tonight, I was actually procrastinating when working with unity), but I'll let you know what happens. Again, thank you both very much for the help, I was completely unaware of virtually everything you said until now. I'll try to work on it tomorrow. (:

avatar image pulsusego · Oct 28, 2013 at 07:55 PM 0
Share

Yep, using parts of both suggestions I got it working wonderfully; thank you both again very much, I appreciate the help.

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

17 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 avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

How Do I Make A Health Bar 6 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

why when i try to add my script to the "player" it says can not can not add script 1 Answer


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