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 Tom 18 · Apr 23, 2011 at 07:57 PM · javascriptif-statements

Strange errors in javascript

Im trying to make a spam check for my game, where the player cannot instantiate any more objects so long as there is one already on the field. To do this ive simply added a variable ( a bool really, but its a float) that is increased when the ball is instantiated and decreased when it is destroyed.

But for some reason after putting in my if statement, it gives me weird errors. Im not that well versed in Javascript as i am in C#, so perhaps my if statement is wrong, but im not sure.

the errors are telling me to insert semicolons where they dont belong.

static var ballCheck : float = 0; var arrow : GameObject; var power : float = 200;

function Update() { if ( Input.GetKeyDown( KeyCode.Mouse0 ) ) { if (ballCheck == 0;) { var anArrow = Instantiate( arrow, transform.position, transform.rotation ); //anArrow.rigidbody.AddForce( transform.forward * power ); TextBoxPoints.points -= 1; ballCheck++; }

 }

}

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

Answer by Tom 18 · Apr 23, 2011 at 08:01 PM

Well it turns out i left a semicolon after my condition.

nevermind then.

Comment
Add comment · Show 3 · 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 Joshua · Apr 23, 2011 at 08:08 PM 0
Share

Yeah xD first thing I noticed :p please delete the question :)

avatar image Justin Warner · Apr 23, 2011 at 08:12 PM 0
Share

Don't delete, just mark your answer as correct =).

avatar image Tom 18 · Apr 25, 2011 at 02:54 PM 0
Share

i gotta wait 5 more hours to mark my own question :|

avatar image
0

Answer by Teare · Apr 23, 2011 at 08:07 PM

Nice of you to catch your own mistake there.

Not sure if this is C# migratory thing, but I prefer to keep the { brackets in the same line as the if statement. I come from an Actionscript background though, and I just found it easier to organize that way.

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 Tom 18 · Apr 25, 2011 at 02:54 PM 0
Share

learning C# i always preferred to leave them below so they are in line with the }. easier for me to read. thats how my instructor did i too so thats probably a contributing factor

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

No one has followed this question yet.

Related Questions

Audio not playing [Fixed] 1 Answer

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

BCE0022 Cannot convert 'function(): String' to 'String'. 2 Answers

[JS - 4.6 - UI issue] my script doesn't allow me to change the items text 1 Answer

EXTREMELY basic scripting question. 2 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