Windows find nearest instance of object with certain variable value

ikonhero

Member
I need an object to find the nearest instance of an object of a certain type that has a certain value stored as a variable.

For instance obj_a has to find the nearest obj_b that has a variable set as: available = 1;.

Is it possible to implement this as code without having to use multiple variations of obj_b?

Thanks!

(gamemaker 1.4 on Windows.)
 

TheouAegis

Member
You could have googled this.

Code:
var d=0, dist = $FFFFFFFF, targ = noone;
with obj_b
if available == 1 {
d = point_distance(x,y,other.x,other.y);
if d < dist {
dist = d;
targ = id;
}
}
if targ != noone {
/* whatever you want to happen */
}
 
Top