- Home /
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!
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 ;
}
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.
How would I go about what to use in place of -13?
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.
Your answer
Follow this Question
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