Correct...Just a little modification:
checkdistance:
maxdist#=0.0
for obj=firstobj to lastobj
diffx#=object position x(player)-object position x(obj)
diffy#=object position y(player)-object position y(obj)
diffz#=object position z(player)-object position z(obj)
distance#=sqrt(diffx#^2+diffy#^2+diffz#^2)
if distance#<maxdist# or maxdist#=0.0 then closest=obj:maxdist#=distance#
next obj
return
This will go through the objects and find the closest one, no matter how close it is. The "closest" variable that is returned will be the object number of the closest object. This code uses all three dimensions, like a sphere. The abs() functions are not needed because when you square a number it always ends up positive.
Good Luck
Xander - Bolt Software
Don't pat yourself on the back too often, you might hurt yourself