var idd;var sqr_distance;var xx, yy;idd=0;sqr_distance=-1;//default distancexx=x;yy=y;with apple{ if (sqr_distance==-1||sqr(xx-x)+sqr(yy-y)<sqr_distance) { sqr_distance=sqr(xx-x)+sqr(yy-y); idd=id; }}//idd is the id of the nearest apple. If idd=0, then there are no apple instances in the room
instance_nearest(x,y,obj) Returns the id of the instance of type obj nearest to (x,y). obj can be an object or the keyword all.
Quote from: Help fileinstance_nearest(x,y,obj) Returns the id of the instance of type obj nearest to (x,y). obj can be an object or the keyword all.Put apple for obj? Looks like it should work..