Sorting objects by property-values

I need help! Iam scripting the Bots for my game, and I got problems with this: The pathfinding is based on Nodes, wich have different properties. The bot needs to choose a Node (the one with the lowest property-value).

Ah and the Bot detects the Nodes with an radar-sensor

this depends on your pathfinding strategy.
if you want to use a radarsensor, it seems you want to use a strategy without memory.

Here is what you can do



Pvalue ="prop"
radaredObjects = radarSensor.hitObjectList

if radaredObjects==None or len(radaredObjects)<1:
  # nothing in radar cone
  return 

objectWithLowestPropValue = None

for object in radaredObjects:
  if Pvalue in object:
    if objectWithLowestPropValue == None:
      # the first object with the property
      objectWithLowestPropValue = object
    else:
      if object[Pvalue] < objectWithLowestPropValue[Pvalue]:
        # this one has a lower value
        objectWithLowestPropValue = object

if objectWithLowestPropValue  == None:
  print "nothing found"
  return

print( "object "+ str(objectWithLowestPropValue) +" with value "+str(objectWithLowestPropValue[Pvalue]) + " found"

That gives you the object with the lowest property. Just typed in, not tested. It might contain some errors.
Sorting needs a different method.

WOW Monster! You are a legend!
Thank you soooo much! It works perfectly :slight_smile:
I will credit you, definately.

you rock!