Hi,
you will need to modify back to zero the 'distance' variable once reached the total length by converting the 'walking_speed' variable to a negative value.

You will need to get the total length of a path by 'path_length' before the loop.
Code:
var nPathLength = path_length ( me );



Then check the distance value inside the loop and switch the walking speed variable sign.
Code:
nDistance += nWalkingSpeed * time_step;
if ( ( nDistance < 0 ) || ( nDistance > nPathLength ) )
{
   nWalkingSpeed *= -1;
   nDistance = clamp ( nDistance, 0, nPathLength );
}



There are a couple of troubles in your code. You declared 'last_pos' and 'direction' as arrays of three vector structs. You only need one vector struct each.
Code:
VECTOR vecDirection; // A single vector struct
VECTOR vecDirection[3]; // An array of vector structs
VECTOR *vecDirection; // A single pointer to a vector struct
VECTOR *vecDirection[3]; // An array of pointers to vector structs



You modify the 'distance' variable by adding the 'walking_speed' constant value. This method is framerate dependant. You need to multiply it by 'time_step' in order to certainly convert a speed to a distance in reference to a time lapse.

Hope it helps. Salud!