A thing that you can change if you want it to be so that the property does not have to be true is, on the line that says:
obj_list = [obj for obj in GameLogic.getCurrentScene().objects if obj.get(prop)]
Just change it to:
obj_list = [obj for obj in GameLogic.getCurrentScene().objects if obj.has_key(prop)]
The quotes around it show that it is a list. All it is doing is getting all the objects in the scene then adding them to the list if obj.get(prop) == True.
EDIT:
Its the same thing as doing this:
obj_list = []
for obj in GameLogic.getCurrentScene().objects:
if obj.get(prop) == True:
obj_list.append(obj)
Its called “list comprehension”, each iteration adds an element to the list. You can give it a google for some better explinations that what I can give, but basically it lets you construct lists with some elegance I guess.
:o hum… I’m a little shy to ask this so newbish question but… what does it do exactly ? I know its supposed to get you to the closest object with the prop “yourpropname”… but how would I implement this into a game ? How does the object move ? Does it face the object it goes to ? How can we adjust speed ?
I’m not requesting a tutorial, its just that I’m a little confused.
It gets all the objects in the scene, then if the object has the defined property, it adds it in the list. Then it sorts the list by distance, and gets the closest one from you.
That is all the script does, you can add speed, tracking etc. if you want.