var/obj/GotoWood/closest var/dist for(var/obj/GotoWood/GW in world) if(!closest) //set the first obj closest = GW dist = get_dist(src,GW) else if(get_dist(src,GW)<dist) //if the current GW is closer than the one we previously had closest = GW //make the current GW our closest one dist = get_dist(src,GW)
What the above does is it loops through every /obj/GotoWood in the world. The first obj it finds it automatically sets as the closest. When it finds another obj, it checks if the distance between src and the new obj is less than the distance between src and the closest obj. If it is, then the current obj now is our closest obj. If it isn't, then it continues looping through all the /obj/GotoWood in the world.
Ask, with very specific questions, if you don't understand.