NearList problem!

How can I get the object name
that have the lowest dist(property value) in a near.getHitObjectList()

I´ve tried

if obj.dist>=obj.dist:
didn´t help

any help would be apriciated

Is the dist() a gamelogic function?
I’ll assume no, but maybe I missed it somewhere. Anyway, get the distance to each object:
and then do a comparison.

distance = 1000.0
name = ""
for obj in near.getHitObjectList():
   thisDistance = dist(owner.getPosition(),obj.getPosition())
   if thisDistance < distance
      distance = thisDistance
      name =

I´ve made so that specific obj in nearlist calculates the distance and made obj.dist(their property(type float))have the value of the distance difference

now what I´m trying to do is to get the name of the object that has the least dist value from the nearlist through compairing

So I then could make the character track to that object

any help would be apriciated

Same principal and almost the same code:

distance = 1000
name = ""
for obj in near.getHibObjectList():
    if obj.dist < distance:
          distance = obj.dist
          name =
print name

Start by setting the distance higher than anything could be in the near list
and making a name variable

Cycle through the object list, if the obj.dist is lower than the original or than the one before, then we
make distance equal to it and get it’s name. Eventually, name will be the lowest obj distance. Then print it. This is also something you could do while finding the obj.dist. Just store the value and name of the one that came before, if the new value is lower, then store it as the value and store it’s name.

didn´t work either:(

can I get like the first and second obj and than manualy assign let say obj1.track=1

cause if so I think I can make

if obj1.dist<obj2.dist and obj1.dist<obj3.dist:
if obj1.track==1:

If it didn’t work it’s probably because your dist function isn’t working. It’s a very simple concept. Put some numbers in a list and try it out. Print out your dist function results and the name of each object. I guarantee you if the objects have a dist that are not zero or at least different, if there are objects in the near list, and the lowest distance is less than 1000, it will work.