How do I keep my NPCs 'interested'?

Like much of what I'm doing as a beginner, I'm using someone else's code here as a starting point. I've got a script that makes my NPCs chase a player character once it is within a certain range:

// This is the object to follow
var leader : Transform;

// This is the object which follows
var follower : Transform;

// This is the speed with which the follower will pursue
var speed : float = 2.0;

// This is the range at which to pursue
var chaseRange : float = 10.0;

// This is used to store the distance between the two objects.
private var range : float;

function Update(){

   // Calculate the distance between the follower and the leader.
   range = Vector3.Distance( follower.position,leader.position );

   if ( range <= chaseRange ){

      // If the follower is close enough to the leader, then chase!
      follower.LookAt(leader);
      follower.Translate( speed * Vector3.forward * Time.deltaTime);

   } // End if (range <= chaseRange)

} // End function Update()

All good - but I don't want them to stop chasing. I basically want the NPCs to be 'activated' once the player character first comes within range, and then never stop chasing until they catch it. I just don't know what to do with that if statement to achieve this effect.

You just need to add a 'flag' (a boolean variable) which starts as false, and is set to true when the player comes in range. Then only execute your chasing code when this flag is true.

The modified script would look like this:

// This is the object to follow
var leader : Transform;

// This is the object which follows
var follower : Transform;

// This is the speed with which the follower will pursue
var speed : float = 2.0;

// This is the range at which to pursue
var chaseRange : float = 10.0;

// This is used to store the distance between the two objects.
private var range : float;

// This is the flag which indicates whether chasing has started
private var chasing : boolean = false;

function Update(){

   // Calculate the distance between the follower and the leader.
   range = Vector3.Distance( follower.position,leader.position );

   if ( !chasing && range <= chaseRange ) {
       chasing = true;
   }

   if ( chasing )
   {

      // If the follower is close enough to the leader, then chase!
      follower.LookAt(leader);
      follower.Translate( speed * Vector3.forward * Time.deltaTime);

   } // End if (range <= chaseRange)

} // End function Update()