0
$\begingroup$

I have a number of objects with the boolean property, and I need to write a script which specifies any object which has this property and whose value is set to True. I don't know how to phrase a definition for such an object though.

$\endgroup$
1
$\begingroup$
import bge

def findObjectByPropertyValue(propertyName, propertyValue):
    return [object for object in bge.logic.getCurrentScene()
            if propertyName in object and object[property] == propertyValue]

Alternative (This does not allow to search for value None as it can't distinguish between value None and not-present):

import bge

def findObjectByPropertyValue(propertyName, propertyValue):
    return [object for object in bge.logic.getCurrentScene()
            if propertyName.get(property) == propertyValue]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.