LoD help: property check?

Hello again… Just wondering how to check if an object has a property in a python script without using a “near” sensor or something of the like. I have:


import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner


for i in range(0, len(scene.objects))
    subject = scene.objects[i]

    if subject.has_key("lod"):
#      ^this here is my problem...

        if own.getDistanceTo(subject) > subject["lod"]:
            subject.visible=0

I got “has_key” from another script, but honestly I have no idea what it does. Thanks!

I don’t think has_key works with modern blender, i think you need to use “get”.

Try here:
get

do not use has_key it is deprecated

Better use the “in” operator.

Have a look at the BGE Guide to Python coding it explains all three methods to deal with properties (existing and not existing onces).

Btw. Objects are not subjects (the term subject is used in conjunction with message sensors/actuators)


import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner

for subject in scene.objects :
    if "lod" in subject : 
        if own.getDistanceTo(subject) > subject["lod"] : 
            subject.visible=0


Excellent. Thanks, guys! :smiley: