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 bpears · Jan 23, 2013 at 08:48 PM · javascriptformat

Format correct? Unity script - one line snippet

 var equipped = true;

This line of code is getting ignored for some reason

 if(equipped && Input.GetKeyDown ("e"))&&(someNumberVar >= (anotherNumberVar)){
                 Debug.Log("number vars compared");
Comment
Add comment · Show 11
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 bpears · Jan 23, 2013 at 08:54 PM 0
Share

I have a similar if statement that uses !equipped and it works, so I don't know why this one isn't. if(equipped) is how you say equipped is true inside an if statement right? Since it was already previously defined as true?

avatar image Wolfram · Jan 23, 2013 at 09:03 PM 0
Share

Not a master of JS, but I'd suggest declaring the type:

 var equipped:bool = true;
avatar image Dave-Carlile · Jan 23, 2013 at 09:06 PM 3
Share

Log everything before the if. The value of equipped, the result from Input.Get$$anonymous$$eyDown, someNumberVar, and anotherNumberVar. Do the values match what you expect? Do the values all satisfy the conditional?

avatar image Wolfram · Jan 23, 2013 at 09:42 PM 1
Share

So trace back from there. What makes that if run into the else-case? Also, does the line "var equipped = true;" actually exist in your script? If so, maybe you changed the value in the Inspector to "False"?

avatar image Eric5h5 · Jan 23, 2013 at 09:42 PM 1
Share

@Wolfram: JS, like C#, implicitly declares the type if you supply a value. In both C# and JS, this line:

 var equipped = true;

statically types "equipped" as a boolean. It's a compiler feature and has no effect on the actual generated code either way.

Show more comments

1 Reply

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

Answer by Wolfram · Jan 23, 2013 at 08:51 PM

Count your parentheses. Encompass the whole if-condition into one (...).

 if(equipped && Input.GetKeyDown ("e") && someNumberVar >= (anotherNumberVar)){
     Debug.Log("number vars compared");
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 bpears · Jan 23, 2013 at 08:56 PM 0
Share

I do in my actual script. I was just trying to simplify some. But it ignores it either way.

avatar image Wolfram · Jan 23, 2013 at 09:01 PM 0
Share

That explains it - the code you posted shouldn't even compile :-D

Well, if you want us to answer your question, post the actual code. Also, think whether truly all conditions are met.

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

12 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

Related Questions

Multiple Cars not working 1 Answer

Help with movement script 2 Answers

Assets/MELLE.js(1,15): BCE0044: unexpected char: ';'. 1 Answer

How to fix code errors? 1 Answer

Another collision detection issue 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