- Home /
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++; }
}
}
Answer by Tom 18 · Apr 23, 2011 at 08:01 PM
Well it turns out i left a semicolon after my condition.
nevermind then.
Yeah xD first thing I noticed :p please delete the question :)
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.
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

Follow this Question
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