targetball = null
Distance = 100000
for ball = firstball to lastball
if entitydistance(ball,bat)<Distance
Distance = entitydistance(ball,bat)
TargetBall = ball
endif
next
Distance = 100000
for ball = firstball to lastball
if entitydistance(ball,bat)<Distance
Distance = entitydistance(ball,bat)
TargetBall = ball
endif
next