I’m not sure what you want to do with the result, but this expression will fill the frames array with all the frames where a close encounter first occurs. However, on each frame, this expression has to examine the entire comp, so you might want to consider converting the expression to keyframes at some point if processing time becomes an issue:
var rangeMin = 100;
var posDistance = effect("Shortest Distance")("Slider");
frames = [];
inRange = false;
for (i = 0; i <= timeToFrames(thisComp.duration); i++) {
if (inRange){
if (posDistance.valueAtTime(framesToTime(i)) > rangeMin){
inRange = false;
}
}else{
if (posDistance.valueAtTime(framesToTime(i)) <= rangeMin){
frames.push(i);
inRange = true;
}
}
}