Error in Enemy AI script need help to fix it.

This script I’m trying to combine 2 functions first one is to have enemies to wander around the game and second is to have them attack player when it gets into distance, having problem with one of the lines asking for “:” instead of a semi-colon. Any help to figure out how to fix it is much appreciated.

var speed : float;
var isWalking : boolean = true;

var distance;
var target : Transform;
var lookAtDistance = 15.0;
var attackRange = 10.0;
var moveSpeed = 5.0;
var damping = 6.0;
private var isItAttacking = false;

function Start () {

randomRotation ();

}

function Update () {

 distance = Vector3.Distance(target.position, transform.position);

if(distance < lookAtDistance)
{
isItAttacking = false;
renderer.material.color = Color.yellow;
lookAt ();
}
if(distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if(distance < attackRange)
{
attack ();
}
if(isItAttacking)
{
renderer.material.color = Color.red;
}
{
this.transform.Translate(Vector3.forward * speed);
}

}

function FixedUpdate () {

rigidbody.AddForce (Vector3.down * 500);

}

function randomRotation () {

while(isWalking){

	yield WaitForSeconds(Random.Range(5,10));
	transform.eulerAngles = Vector3(0, Random.Range(0, 360), 0);
} 

}

function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}

function attack ()
{
isItAttacking = true;
renderer.material.color = Color.red;

transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);

}

the error code is this
Assets/Scripts-FPS/Enemy AI.js(47,58): BCE0044: expecting :, found ‘;’.

I’m new to java script been looking around for answers on vid tutorials and Unity answer, can’t seem to find one to solve my script error.

Just remove the extra curly brackets you have surrounding this.transform.translate

{
   this.transform.Translate(Vector3.forward * speed);
}

Are you sure you’re not forgetting an if statement here?

if (somethingHappens)
{
   this.transform.Translate(Vector3.forward * speed);
}

If not, just remove the brackets altogether.

And btw there’s no need to say this, this refers to the current object you’re currently working on. You’re already in it so there’s no need for that. Just say transform.Translate...

You normally use the this keyword when one of the parameters you’re passing to your function/method has the same name as one of your data fields, like:

var myVar : myDataType;

function myFunc(myVar : myDataType)
{
   this.myVar = myVar;
}

this.myVar refers to your data field myVar, while just myVar refers to the function parameter myVar

I also advise you to cache the transform component since you’re using it a lot. calling transform from anywhere is the equivalent of doing GetComponent< Transform >() which could effect your performance if you’re doing it a lot, in your Update for example. So, cache it:

private var cachedTransform : Transform;

function Awake()
{
   cachedTransform = transform;
}

Now, use cachedTransform instead of transform in your Update, or wherever.