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 LightSource · Sep 05, 2013 at 01:33 AM · javascripterrorsyntax

Syntax errors?

Hey all, I seems to be getting basic syntax errors on what I thought was a clean script. Seems like a curly bracket problem, but their all fine (I think?), I checked them multiple times. The earliest error is:

 (62,14): BCE0044: expecting (, found 'generateFloor'.

My code:

 var movementSpeed : float = .001;
 var x : int = 0;
 
 var Cube : Transform;
 var Empty : Transform;
 
 var startSize : int = 25;
 var chances : int;
 
 var generate : boolean = false;
 
     function Start () {
         //Move
         transform.Translate(Vector3.left * movementSpeed, Space.World);
     }
     
 //********************************
 //Raycast
 //********************************
  
       function Update () {
       
         var up = transform.TransformDirection(Vector3.up);
          var hit : RaycastHit;
          
          Debug.DrawRay(transform.position, up * 10, Color.green);    
                   
                   if (Physics.Raycast (transform.position, up, hit)) {
                        generate = true;
       }
     
          
 //********************************
 //Generate chances
 //********************************  
      
      chances = Random.Range (1,101);
  
     
         if (generate == true) {
         
             if (chances <= 100) {
             generateFloor();
             }
         
             if (chances <= 0) {
             generateDrop();
             }
         
             if (chances <= 0) {
             generatePlatform();
             
             }
     }
     
 //********************************
 //Generate level
 //********************************  
    
     function generateFloor () {
      Instantiate (Cube, transform.position + Vector3(startSize, 0, 0), Quaternion.identity);
      generate = false;
     }
     
     function generatePlatform() {
     Instantiate (Cube, transform.position + Vector3(startSize, 1, 0), Quaternion.identity);
     generate = false;
     }
     
     function generateDrop() {
     Instantiate (Empty, transform.position + Vector3(startSize, 0, 0), Quaternion.identity);
     generate = false;
     }
     
  
  //*********************************//
     function OnBecameInvisible () {
      Destroy(gameObject);
     }
     
     }
     
     
     


Please, please, please ask for details if you need them and if this big block of code is to intimidating for a more casual forum, I will delete the question gladly. Thanks.

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

2 Replies

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

Answer by clunk47 · Sep 05, 2013 at 02:16 AM

A couple braces '}' are missing. I usually format my code like the following so these are easier to spot. I also would use a new variable for instantiations, so they act like a "Clone" of your prefab, to avoid data loss if the objects are destroyed.

 #pragma strict
 
 var movementSpeed : float = .001;
 var x : int = 0;
 var Cube : Transform;
 var Empty : Transform;
 var startSize : int = 25;
 var chances : int;
 var generate : boolean = false;
 
 function Start () 
 {
     //Move
     transform.Translate(Vector3.left * movementSpeed, Space.World);
 }
 
 //********************************
 //Raycast
 //********************************
 
 function Update () 
 {
     var up = transform.TransformDirection(Vector3.up);
     var hit : RaycastHit;
     Debug.DrawRay(transform.position, up * 10, Color.green);    
     
     if (Physics.Raycast (transform.position, up, hit)) 
     {
         generate = true;
     }
     
     //********************************
     //Generate chances
     //********************************  
     
     chances = Random.Range (1,101);
     
     if (generate == true) 
     {
         if (chances <= 100) 
         {
             generateFloor();
         }
         
         if (chances <= 0) 
         {
             generateDrop();
         }
         
         if (chances <= 0) 
         {
             generatePlatform();
         }
     }
 }
 
 //********************************
 //Generate level
 //********************************  
 
 function generateFloor () 
 {
     var newCube = Instantiate (Cube, transform.position + Vector3(startSize, 0, 0), Quaternion.identity);
     generate = false;
 }
 
 function generatePlatform() 
 {
     var newCube = Instantiate (Cube, transform.position + Vector3(startSize, 1, 0), Quaternion.identity);
     generate = false;
 }
 
 function generateDrop() 
 {
     var newCube = Instantiate (Empty, transform.position + Vector3(startSize, 0, 0), Quaternion.identity);
     generate = false;
 }
 
 
 //*********************************//
 function OnBecameInvisible () 
 {
     Destroy(gameObject);
 }
 
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 LightSource · Sep 05, 2013 at 08:21 PM 1
Share

Did you actually just re-format my code? Awesome!

avatar image
1

Answer by weenchehawk · Sep 05, 2013 at 01:56 AM

Seems to me like your update() function is missing a closing curly brace }.

your indentation (as it shows above) seems to confuse line 40's opening brace and the closing braces on line 53 & 54

The brace on line 53 belongs to the if on line 50,

The brace on line 54 belongs to the if on line 40

leaving no closing brace.

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 Tarlius · Sep 05, 2013 at 02:05 AM 0
Share

Seems correct. Be careful indenting your code and you should never have this problem. Count yourself lucky that this time actually gave you a compile error.

avatar image LightSource · Sep 05, 2013 at 08:21 PM 0
Share

I'll keep that in $$anonymous$$d. Cluck47 got the answer first though, but thank's alot for the answer!

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

18 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

Related Questions

Script error with turrets 5 Answers

Simple syntax error that I can't seem to find 2 Answers

Javascript syntax errors with basic expressions 2 Answers

Mouse look script help 1 Answer

Help solving for loop error 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