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 pookiw · Apr 04, 2013 at 09:11 AM · errorassignment

Scripting Errors I cannot fix, Could use a helping hand and someone to tell me how to fix it.

Hello everyone, just getting started with Unity and Javascript and have started debugging a script my teacher provided us, I have managed to do most of it but have one error popping up here. If anyone is willing to help me fix the errors and describing what is wrong with and and how to fix it I would be super thankful. Thanks alot

 public var speed : float = 2;            // movement speed
 public var patrolDistance : float = 10;    // how far to patrol
 
 public var alert : Bool = false;        // is alert to player's presence?
 
 private var player : Transform;                    // reference to the player's transform
 private var patrolledSoFar : float = 0;            // current progress through patrol
 
 function Start()
 {
     // get reference to CC
     controller = GetComponent(CharacterController);    
     // find player using tag
     player = GameObject.FindWithTag("Player").transform;
 }
 
 function Update()
 {
     // if the player has been spotted...
     if(alert)
     {
         // search and destroy
         transform.LookAt(player);
     else    // if the player is undetected  //first error Here says "expecting }, found "else" 
     {
         // patrol
         patrolledSoFar == speed * Time.deltaTime; //Second error says "expecting :, found ";" 
         if(patrolledSoFar == patrolDistance)
         {
             transform.Rotate(0, 180, 0);
         }
     }
     // always move
     controller.Move(transform.forward * speed * Time.deltaTime);
 }
Comment
Add comment · Show 2
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 Fattie · Apr 04, 2013 at 10:57 AM 0
Share

As you can see people are happy to help! be sure to TIC$$anonymous$$ an answer when you are finished, to close out the question. Also THU$$anonymous$$B any useful answers!

avatar image pookiw · Apr 04, 2013 at 03:14 PM 0
Share

Thanks alot for the help, I always feel kinda lame when I have to ask someone to point out something easy in Java, but I really am grateful for your help, and thank you for labeling the errors.

2 Replies

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

Answer by xolan · Apr 04, 2013 at 10:49 AM

First thing in Java there isnt a variable type called "Bool" instead you should use "boolean".

so the corect way to write the alert variable would be:

 var alert:boolean = false;

Yea and I found a couple of syntax errors. The script should be somthing like this.

 var speed:float = 2;
 var patrollDistance:float = 10;
 var alert:boolean = false;
 private var player:Transform;
 var patrolledSoFar:float = 0;
 
 function Start()
 {
      controller = GetComponent(CharacterController)
      player = gameObject.FindWithTag("Player").transform;
 }

 function Update()
 {
      //See if the player has been spotted
      if(alert == true)
      {
          transform.LookAt(player);
      }  //This is the first error. You havent placed the closed bracket so it says(Expecting "}" found else)
      else
      {
          patrolledSoFar = speed * Time.deltaTime; //Here only goes one "="
          if(patrolledSoFar == patrollDistance)
          {
               transform.Rotate(0,180,0);
          }
      }
      //Making it always moving can be done like this
      transform.position += transform.forward * speed //This is only if your method doesent work if it does leave it as it is.
 }



Thats about all the scripting you need as far as I could read the script and what you wanted to do with it.

I hope I helped

Comment
Add comment · Show 1 · 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 Jessy · Apr 04, 2013 at 04:29 PM 1
Share

That language is not called Java.

avatar image
1

Answer by Chronos-L · Apr 04, 2013 at 10:41 AM

 #pragma strict
 
 public var speed : float = 2;           
 public var patrolDistance : float = 10; 
 
 public var alert : boolean = false;        
 
 private var player : Transform;                 
 private var patrolledSoFar : float = 0;        
 
 // You need this line or else
 // you will get BCE0005: Unknown identifier: 'controller'
 private var controller : CharacterController;
 
 function Start()
 {
     controller = GetComponent(CharacterController); 
     player = GameObject.FindWithTag("Player").transform;
 }
 
 function Update()
 {
     if(alert)
     {
         transform.LookAt(player);
     } // <- the missing "}", You need this to close the if block. 
       //    Fixing this also fix the "expecting :, found ";"  down there
     else   
     {
         //I got a "BCE0034: Expressions in statements must  
         //only be executed for their side-effects." after I 
         //fix both error by adding a } to close your if block.
         //BCE0034 is caused by the '==', it should be '='
         patrolledSoFar = speed * Time.deltaTime; 
 
         if(patrolledSoFar == patrolDistance)
         {
             transform.Rotate(0, 180, 0);
         }
     }
 
     controller.Move(transform.forward * speed * Time.deltaTime);
 }
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

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

Error: error CS0029: Cannot implicitly convert type `UnityEngine.GameObject[]' to `UnityEngine.GameObject 1 Answer

Main Menu Script Issues 1 Answer

BCE0043: Unexpected Token: Contact Error 1 Answer

Cannot compile .exe with specific .dll. (but with other .dlls created the same way) 0 Answers

My jump script isn't working? 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