- Home /
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");
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?
Not a master of JS, but I'd suggest declaring the type:
var equipped:bool = true;
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?
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"?
@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.
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");
I do in my actual script. I was just trying to simplify some. But it ignores it either way.
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
Follow this Question
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