Thanks for your replies, gentlemen. That's what I was hoping, that it was an error on my part! That means that my function could work.
Now, if you would be so kind, would one of you please tell me what I am doing wrong with my code? Like I said, this is my first time writing a function, so I'm not surprised that I have some mistakes.
What I'm trying to make is an improved "nearestobject" function. Basically, it will find the nearest object out of an array of object types, instead of just finding the nearest object of just one type. Hence, instead of just saying: nearestobject [player, "SoldierWB"], you could say: [player, ["SoldierWB","SoldierEB","SoldierGB"]] call nearestobject. Sounds good, right? It's about as close to a nearestobject [unit,
class] as you can get in OFP1. Anyway, here is the code:
private ["_center", "_objectList", "_lowestDist", "_i", "_max", "_object", "_dist", "_closestObject"];
_center = _this select 0;
_objectList = _this select 1;
_lowestDist = 99999;
_i = 0;
_max = count _objectList;
While {_i < _max}
Do
{
_object = nearestObject [_center, _objectList select _i];
_dist = _center distance _object;
If (_dist <= _lowestDist) Then
{
_lowestDist = _dist;
_closestObject = _object;
};
_i = _i + 1;
};
_closestObject
Any help would be greatly appreciated!