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 Theturtlewizard · May 25, 2015 at 04:36 AM · javascripterror

EOF error in my javascript code

Hello everyone, Before I start withe my problem: I'm very new to the Unity scene and don't have a ton of Javascript experience in general.

I have been writing some code for a triple jump 2D sprite in javascript and it looks like this:

  #pragma strict
 
 var isonground : boolean = true;
 var jumpKey : KeyCode;
 var speed : float = 125;
 private var jumpCount : int = 0;
 
 function Update () 
 {
 
 var currentPos : float = GetComponent.<Rigidbody2D>().position.y;
 if (currentPos == -13);
 
 else;
 {
 var isonground : boolean = false;
 }
     if (Input.GetKey(jumpKey));
     {
         if (isonground == true);
             {
             if (jumpCount >= 3);
                 {
                 GetComponent.<Rigidbody2D>().velocity.y = 0;
                 }
             else;
                 {
                 GetComponent.<Rigidbody2D>().velocity.y = speed;
                 var jumpCount = jumpCount +  1;
                 }
             }
         else;
         {
             GetComponent.<Rigidbody2D>().velocity.y = 0;
         }    
     }
 
     else;
     {
         GetComponent.<Rigidbody2D>().velocity.y = 0;
     }
 
 }

I have been receiving the errors :
"Assets/JumpController.js(26,25): BCE0044: expecting }, found 'else'.

Assets/JumpController.js(32,17): BCE0044: expecting }, found 'else'.

Assets/JumpController.js(36,9): BCE0044: expecting EOF, found '}'.

With this being said I've looked over it over and over but still can't find whats wrong, I've also looked for other questions like this and found that it is a problem with the curly brackets, but I can't find were my error is.

Thanks in advance!

Comment
Add comment · Show 5
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 sethuraj · May 25, 2015 at 04:28 AM 2
Share

You should go through some basic Java tutorials before getting into unity the way you wrote the code is wrong.The semicolon is used to end a statement.You should not use it right after if(condition) or else,or like right after any keywords

the syntax of if() is

 if(condition)
 {
   statement ;
 }
 else
 {
   statement ;
 }
avatar image Eno-Khaon · May 25, 2015 at 05:24 AM 1
Share

Also, just a heads up before the situation is remedied and such...

 if (currentPos == -13)

That if condition is almost guaranteed to never, EVER occur. Even if a float value is practically equal to -13, it's still almost definitely not going to be exactly equal to -13.

avatar image Theturtlewizard · May 25, 2015 at 05:26 AM 0
Share

How would I go about what to use in place of -13?

avatar image 3ddave · May 25, 2015 at 06:01 PM 0
Share

The proper way to compare floating point numbers for equality is by giving a margin of error on each side of the value. This value is typically called "epsilon." Here is a good example of what I mean: $$anonymous$$athf.Epsilon.

avatar image Theturtlewizard · May 25, 2015 at 06:22 PM 0
Share

Thanks a lot! Really helped!

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

game won't work in build 0 Answers

Ball jumping mechanic, scrip errors. 1 Answer

[UNSOLVED] Object reference not set to an instance of an object 0 Answers

controlling rigidbody 2d 0 Answers

Unity freezes when I add a special 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