Page MenuHomeFeedback Tracker

nearestObject returns itself if same classType is used
New, WishlistPublic

Description

Hi Adam ;)

I'm not sure if this works as intended but it shouldn't

if you search an Object from an Object with the "nearestObject"-command and use a className of the same Type it returns itself

as example:
nObject = nearestObject [bobCat, "Tank"]; ==> bobCat (where bobCat is a B_APC_Tracked_01_CRV_F)

Reason of this is a function where the bobCat should be able to tow vehicles of all Sorts (Mainclasses are "Car", "Tank" "Air" and "Ship_F") with an action menu entry (like this: this addAction ["Tow Car","tow.sqf", ["Car"], 1, false, true, "","((getposatl _target) distance (getposatl (nearestObject [_target, 'Car']))) < 10"];)
While it works with different Class-Types perfectly the same Classes are not useable

A possible workaround is: use tanks for all exept tanks but if the nearestObject would ignore the object it starts from would be much more effective and at least for me more logical

Details

Legacy ID
884503992
Severity
None
Resolution
Open
Reproducibility
Always
Category
Scripting
Steps To Reproduce

In Editor place a tank(tankA) and another tank (tankB)
give both names
in the init-Field of tankA insert:
this addAction ["Tow Tank","tow.sqf", ["Tank"], 1, false, true, "","((getposatl _target) distance (getposatl (nearestObject [_target, 'Tank']))) < 10"];

as you can see it should show the action in 10m proximity to another tank but it is shown after mission start

Second Test:
In Editor place a tank(tankA) and another tank (tankB)
give both names

exec this code and see the result:
systemchat str nearestObject [tankA, 'Tank'];

systemChat will write tankA

Event Timeline

Syr3L edited Steps To Reproduce. (Show Details)Feb 8 2016, 10:30 PM
Syr3L set Category to Scripting.
Syr3L set Reproducibility to Always.
Syr3L set Severity to None.
Syr3L set Resolution to Open.
Syr3L set Legacy ID to 884503992.May 8 2016, 1:41 PM
Bohemia added a subscriber: Syr3L.Feb 8 2016, 10:30 PM

This sounds like intended behaviour.

"nearestObject [Tank1,'Tank']" means: "the tank nearest to Tank1's POSITION", not "the nearest other tank to Tank1".

Maybe this command could use a little expanding though. Like some commands have an optional parameter for ignored objects ->
"nearestObject [Tank1,'Tank',ignoreObj]"

PiepMGI added a subscriber: PiepMGI.May 8 2016, 1:41 PM

In such case, nearestObjects does the job! and have a look at nearEntities as well (faster).

Perhaps instead of using the original tank object for position, you can use array position which is offset from the tank and so that when you have another tank closer to that position it would return correct object. In the mean time you can also add a check that the object returned is not the same object as your original tank.

Syr3L added a comment.May 19 2016, 7:36 PM

Yeah there are solutions to this - it made and still do not make any sense to me why - if referenced from an object it should return the object at all - but i guess that's just different opinions and interpretations

It's just like PiepMGI said I would just use the above described line instead a crosscheck and additional lines of code for just that purpose of finding another tank from a tank

Anyway NICE you fixed the problems of the tracker we will hear us sooner than later

Greetz