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 Digital-Phantom · Feb 05, 2015 at 07:05 PM · errorcompilerc# to javascriptexpecting

Unexpected Errors - Need help & explaination plz

Part of a tutorial I'm following has this code in the script -

 if(Physics.Raycast(r, out hit)
         {
             while(!passables.Contans(hit.transform.gameObject.name))
             {
                 if(!Physics.Raycast(hit.point + r.direction*0.1f, r.direction, out hit)
                 {
                     break;
                 }
             }
         }
 

However, I'm getting these two errors -

"Assets/Scripts/CameraOperator2.js(71,43): BCE0044: expecting ), found 'hit'."

"Assets/Scripts/CameraOperator2.js(75,100): BCE0044: expecting ), found 'hit'."

Any ideas/suggestions ???

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 carrollh · Feb 05, 2015 at 07:11 PM 0
Share

I don't typically code in js, but shouldn't that be passables.Contains not Contans? Also you need to close the ) at the end of the first line.

avatar image carrollh · Feb 05, 2015 at 09:25 PM 0
Share

Turns out you are actually missing two parenthesis. One at the end of 43 and one at the end of 47:

  if(Physics.Raycast(r, out hit))
  {
       while(!passables.Contains(hit.transform.gameObject.name))
       {
            if(!Physics.Raycast(hit.point + r.direction*0.1f, r.direction, out hit))
            {
                      break;
            }
       }
  }

2 Replies

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

Answer by HarshadK · Feb 06, 2015 at 01:16 PM

The problem is that there is no need to use 'out' keyword in front of hit in JS (required in C#).

So raycast line becomes:

 if(Physics.Raycast(r, hit))

and

 if(!Physics.Raycast(hit.point + r.direction*0.1f, r.direction, hit))

Now solving this will yield some other errors which are also solved here in this code below:

  #pragma strict
  
  public var selectionHighLight : Texture2D = null;
  public static var selection : Rect = new Rect(0, 0, 0, 0);
  private var startClick : Vector3 = -Vector3.one;
  private static var moveToDestination : Vector3 = Vector3.zero;
  private static var passables : String = ""; //{"Floor"};
  
  function Update()
  {
      CheckCamera();
      CleanUp();
  }
  
  function CheckCamera()
  {
      if(Input.GetMouseButtonDown(0))
      {
          startClick = Input.mousePosition;
      }
      else
      if(Input.GetMouseButtonUp(0))
      {
          if(selection.width <0)
          {
              selection.x += selection.width;
              selection.width = -selection.width;
          }
          if(selection.height <0)
          {
              selection.y += selection.height;
              selection.height = -selection.height;
          }
          startClick = -Vector3.one;
      }
      if(Input.GetMouseButton(0))
      {
          selection = new Rect(startClick.x, InvertMouseY(startClick.y), Input.mousePosition.x - startClick.x, InvertMouseY(Input.mousePosition.y) - InvertMouseY(startClick.y));
      }    
  }
  
  function OnGUI()
  {
      if(startClick != -Vector3.one)
      {
          GUI.color = new Color(1, 1, 1, 0.2);
          GUI.DrawTexture(selection, selectionHighLight);
      }
  }
  
  static function InvertMouseY(y : float)
  {
      return Screen.height - y;
  }
  
  function CleanUp()
  {
      if(!Input.GetMouseButtonUp(1))
      {
          moveToDestination = Vector3.zero;
      }
  }
  
  public static function GetDestination(argumentVariableName : Vector3)
  {
      if(moveToDestination == Vector3.zero)
      {
          var hit : RaycastHit;
          var r : Ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
          
          if(Physics.Raycast(r, hit))
          {
              while(!passables.Contains(hit.transform.gameObject.name))
              {
                  if(!Physics.Raycast(hit.point + r.direction*0.1f, r.direction, hit))
                  {
                      break;
                  }
              }
          }
 
          if(hit.transform != null)
          {
              moveToDestination = hit.point;
          }
              
              return moveToDestination;
      }
  }
  
  

Some of the things that are changed here are:

1) Changed declaration of string

 private static var passables : String = ""; // This is how you initialize an empty string

2) Changed HierarchyType.point to hit.point since there is no 'point' type under HierarchyTpe and I think what you are looking for is point of Raycast Hit.

3) You need to provide a name to the variable that will be passed to your method as I've added below:

 public static function GetDestination(argumentVariableName : Vector3)
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 Digital-Phantom · Feb 06, 2015 at 02:18 PM 0
Share

@Harshad$$anonymous$$ many(repeat infinitely) thanks. I truly appreciate your help.

However I do have a couple of questions - The line you changed to read

 private static var passables : String = ""; // This is how you initialize an empty string
  
 

Was (in the original tutorial) written as-

 private static List<string> passables = new List<string>() {"Floor"};
 

Typically, they added an update tutorial later that says the name "Floor" has to be in the script for it to work.

Does this mean I have to add the word 'Floor' into my String = " " or do I need to somehow add it afterwards (similar to how the original line was written ?

The update tutorial- https://www.youtube.com/watch?v=m-oU2mSZykA

Secondly, you said I need to 'provide a name to the variable that will be passed to your method.'

Why do I need to do that? (please don't take that as I don't believe you, I just want to learn/understand exactly 'why' it is I need to do it)

thanks

avatar image HarshadK · Feb 06, 2015 at 07:05 PM 1
Share

The statement from the tutorial

 private static List<string> passables = new List<string>() {"Floor"};

is for declaring a collection of type string with floor as an element.

And you pass a variable name so that the value passed when that function is called can be accessed through that variable, which you can manipulate in the function definition.

avatar image
1

Answer by VesuvianPrime · Feb 05, 2015 at 07:18 PM

Missing a close bracket here:

alt text

Comment
Add comment · Show 4 · 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 Digital-Phantom · Feb 05, 2015 at 08:31 PM 0
Share

yeah, I thought extra brackets were needed, but when I tried that I got these additional messages

"Assets/Scripts/CameraOperator2.js(71,47): BCE0043: Unexpected token: )."

"Assets/Scripts/CameraOperator2.js(75,104): BCE0043: Unexpected token: )."

???

avatar image VesuvianPrime · Feb 05, 2015 at 08:48 PM 0
Share

If you're getting unexpected tokens it probably means you're missing brackets or semi-colons somewhere. Usually on the line prior to where you're getting the error.

avatar image Digital-Phantom · Feb 06, 2015 at 02:49 AM 0
Share

here's the script in full -

 #pragma strict
 
 public var selectionHighLight : Texture2D = null;
 public static var selection : Rect = new Rect(0, 0, 0, 0);
 private var startClick : Vector3 = -Vector3.one;
 private static var moveToDestination : Vector3 = Vector3.zero;
 private static var passables : String = new String(); //{"Floor"};
 
 function Update()
 {
     CheckCamera();
     CleanUp();
 }
 
 function CheckCamera()
 {
     if(Input.Get$$anonymous$$ouseButtonDown(0))
     {
         startClick = Input.mousePosition;
     }
     else
     if(Input.Get$$anonymous$$ouseButtonUp(0))
     {
         if(selection.width <0)
         {
             selection.x += selection.width;
             selection.width = -selection.width;
         }
         if(selection.height <0)
         {
             selection.y += selection.height;
             selection.height = -selection.height;
         }
         startClick = -Vector3.one;
     }
     if(Input.Get$$anonymous$$ouseButton(0))
     {
         selection = new Rect(startClick.x, Invert$$anonymous$$ouseY(startClick.y), Input.mousePosition.x - startClick.x, Invert$$anonymous$$ouseY(Input.mousePosition.y) - Invert$$anonymous$$ouseY(startClick.y));
     }    
 }
 
 function OnGUI()
 {
     if(startClick != -Vector3.one)
     {
         GUI.color = new Color(1, 1, 1, 0.2);
         GUI.DrawTexture(selection, selectionHighLight);
     }
 }
 
 static function Invert$$anonymous$$ouseY(y : float)
 {
     return Screen.height - y;
 }
 
 function CleanUp()
 {
     if(!Input.Get$$anonymous$$ouseButtonUp(1))
     {
         moveToDestination = Vector3.zero;
     }
 }
 
 public static function GetDestination(Vector3)
 {
     if(moveToDestination == Vector3.zero)
     {
         var hit : RaycastHit;
         var r : Ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
         
         if(Physics.Raycast(r, out hit))
         {
             while(!passables.Contains(hit.transform.gameObject.name))
             {
                 if(!Physics.Raycast(hit.point + r.direction*0.1f, r.direction, out hit))
                 {
                     break;
                 }
             }
         }
             if(hit.transform != null)
             {
                 moveToDestination = HierarchyType.point;
             }
             
             return moveToDestination;
     }
 }
 
 

$$anonymous$$aybe seeing the whole script will help put things in context

avatar image Digital-Phantom · Feb 06, 2015 at 12:58 PM 0
Share

Well... my head is about to explode. If I don't put in the extra brackets it says ) is missing, if I do put them in it says ) is an unexpected token.

Surely one of you guys have some ideas as to what is wrong here?

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

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

Related Questions

What is wrong with these two lines of scripting? 1 Answer

Internal compiler error 2 Answers

Compiler errors while switching to android 1 Answer

Unity Compiler Error Glitched. 0 Answers

Problem with Mono compiler 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