Unexpected token: return

EDITED:

Script:

    if (suspended)
    	(
 40  		return;
    	)
    	if (Input.GetButton(leftButton));
    	(
    		transfrom.rotation.y = leftRotation;
    		transform.Translate(forward * moveSpeed * dt);
    		animation.Play("Walk_");
    	)
    	else if (Input.GetButton(rightButton))
    	(
    		transfrom.rotation.y = rightRotation;
    		transform.Translate(forward * moveSpeed * dt);
    		animation.Play("Walk_");
    	)
    )

function SetSuspension(setting : boolean)
{
	suspended = setting;
)

As you can see, I marked line 40, which is where it says ‘return’. I was on this tutorial:

(better be the right one!)

For the person who created the tutorial, his game worked fine after he saved the script. Mine however did not. I got this error:

Unexpected token: return

If anyone can tell me what this means and how to fix it, I would be very pleased. Thanks

The code you posted is incorrect. Normally I would say do the tutorial again, but here’s what the Update function should look like :

function Update()
{
	if (suspended)
	{
		return;
	}

	if (Input.GetButton(leftButton));
	{
		transform.rotation.y = leftRotation;
		transform.Translate(forward * moveSpeed * dt);
		animation.Play("Walk_");
	}
	else if (Input.GetButton(rightButton))
	{
		transform.rotation.y = rightRotation;
		transform.Translate(forward * moveSpeed * dt);
		animation.Play("Walk_");
	}
}

What this is saying is : if suspended == true, return (don’t go past this point of the function, don’t do anything else this loop).

When coding, always check your parenthesis and curly braces.


Edit : here is the movement script with some corrections I made to the original. This is tested and working. Really there are better tutorials out there that cover input, movement and animation.

#pragma strict


var leftButton : String;
var rightButton : String;

var forward : Vector3;
var dt : float; // double;

var leftRotation : float;
var rightRotation : float;

var suspended : boolean;
var moveSpeed : float; // double;


function Start() 
{
    leftButton = "a";
    rightButton = "d";

    forward = Vector3.forward; // new Vector3( 0, 0, 1 );
    dt = Time.deltaTime;

    leftRotation = -0.7071069;
    rightRotation = 0.7071069;

    suspended = false;
    moveSpeed = 3.0;
}

function Update() 
{
    if ( suspended )
    {
       return;
    }

    //if (Input.GetButton(leftButton))
    else if ( Input.GetKey( leftButton ) )
    {
       transform.rotation.y = leftRotation;
       transform.Translate( forward * moveSpeed * dt );
       animation.Play( "walk" );
    }
    //else if (Input.GetButton(rightButton))
    else if ( Input.GetKey( rightButton ) )
    {
       transform.rotation.y = rightRotation;
       transform.Translate( forward * moveSpeed * dt );
       animation.Play( "walk" );
    }
    else
    {
    	animation.Play( "idle" );
    }
}

function SetSuspension( setting : boolean )
{
	suspended = setting;
}

That semicolon after the if statement is probably ruining everything.

I often make that same mistake myself and it’s easy to overlook.

Also, you’re supposed to use {} for if statements, not (). If it compiles ok… Actually someone told me you don’t need brackets at all to make it work, which is surprising, still, you should just stick to conventions; for example not capitalizing variable names; and life will be better for you.