Getting an error!

Hello there. I keep on getting the error: Assets/Scripts/Player.js(7,32): BCE0044: expecting :, found ‘;’.

I don’t know why. Here is my script:

var PlayerState : float;
var PlayerAnimSec : GameObject;

function Update (){
{

PlayerStateController();
PlayerAnimSec();

}

function PlayerStateController()
{
if ((Input.GetAxis(“Vertical”) !=0 | | Input.GetAxis(“Horizontal”) !=0))
{
(Input.GetButton(“Sprint”))
{
PlayerState = 2;
}
else
{
PlayerState = 1;
}

}
else
{
PlayerState = 0;
}

}
function PlayerAnims()
{
if PlayerState = 0;
{
PlayerAnimSec.animation.CrossFade(“Idle Animation”, 0.4);
}
else if PlayerState = 1;
}
PlayerAnimSec.animation.CrossFade(“Walk Animation”, 0.4);
}
else if PlayerState = 2;
{
PlayerAnimSec.animation.CrossFade(“Sprint Animation”, 0.4);
}

Please help!

Notice that you have two open braces here:

I recommend spending some time learning how to program and debug errors, it will save you a ton of time.

http://forum.unity3d.com/threads/143875-Using-code-tags-properly

–Eric

The syntax of your if statements is also wrong. It should look as follows:

if (theConditionYouAreChecking) {
	// Place all the code in here that has to be executed if theConditionYouAreChecking is true.
	... 
}

Another important aspect is that if you check whether a variable has a certain value, you need to compare with == and not with =.

if (PlayerState == 0) {
	...
}

Thanks so much for your help!

I did everything you all told me and the error disappeared. But now I got another :/.

Assets/Scripts/Player.js(8,1): BCE0044: expecting EOF, found ‘}’.

Post the code :slight_smile:

Don’t forget to use the code tag and indentation would also help a lot for the readability.

Edit: According to the error message, you placed one } too much at this position.

Here is my code as of now

var PlayerState : float;
var PlayerAnimSec : GameObject;

function Update (){
}
	PlayerStateController();
	PlayerAnimSec();

function PlayerStateController(){
}
	if ((Input.GetAxis("Vertical") !=0  | |  Input.GetAxis("Horizontal") !=0)) {
	}
	if (Input.GetButton("Sprint")) {
		}
		PlayerState == 2;
		{
	else
	{
	PlayerState == 1;
	}
	
{
else
}
PlayerState == 0;
{

}
function PlayerAnims() {
}
if PlayerState == 0;
	{
	PlayerAnimSec.animation.CrossFade("Idle Animation", 0.4);
	}
else if PlayerState == 1;
	{
	PlayerAnimSec.animation.CrossFade("Walk Animation", 0.4);
	}
else if PlayerState == 2;
	{
	PlayerAnimSec.animation.CrossFade("Sprint Animation", 0.4);
	}

And this is the error: Assets/Scripts/Player.js(8,1): BCE0044: expecting EOF, found ‘}’.

Sorry to tell you that, but you have obviously no idea how to to code and for that this is way too complex. You don’t understand even the basics about syntax. That’s why I propose you to start with even simpler examples.

I haven’t tested the code, but I expect it should be nearly like that.

var PlayerState : float;
var PlayerAnimSec : GameObject;
 
function Update () {
	PlayerStateController();
	PlayerAnimSec();
}

function PlayerStateController() {
	if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) {
		if (Input.GetButton("Sprint")) {
			PlayerState = 2;
		} else {
			PlayerState = 1;
		}
	} else {
		PlayerState = 0;
	}
}

function PlayerAnims() {
	if (PlayerState == 0) {
		PlayerAnimSec.animation.CrossFade("Idle Animation", 0.4);
	} else if (PlayerState == 1) {
		PlayerAnimSec.animation.CrossFade("Walk Animation", 0.4);
	} else if (PlayerState == 2) {
		PlayerAnimSec.animation.CrossFade("Sprint Animation", 0.4);
	}
}

Did what you told me and got this…

Assets/Scripts/Player.js(10,5): BCE0077: It is not possible to invoke an expression of type ‘UnityEngine.GameObject’.

Help would be appreicated (Im a noob)

Learn to code. There are a lot of tutorials available. That’s the best help I can offer.

Use common sense more when looking at brackets, between your if and else statements your brackets were quite much completely inverse.

{This is between brackets}
(So is this)
[And this]

}but thats what you did { :wink:

Also the console spits out quite exact error messages. In this case an error seems to be at line 10, character 5 of player.js, but looking at your last posted version theres no object reference on line 10, thus rendering this message useless to us without the updated code. (Unless Inpu.GetAxis is not a correct reference you used, but it seems correct to me, it is starting on line 10, ch5 though…)
Maybe by looking at firstpersoncontroller.js (in standard assets) you can find an implication that works :slight_smile: