Setting/Modifying Object Properties?

My problem (forgive me if it’s already been solved before) is I want to add/get the value of/modify the value of an object’s properties with a Python script in 2.55. At best I can get a list of property names and change those but I don’t see any way to modify the value. Is there a way to do this via code?

import bge
cont = bge.logic.getCurrentController()
own = cont.owner

own[“prop”] = 1 #write
xyz = own[“prop”] #read

as in object.property = property
i don’t know if it’s GameLogic, or bge.logic, but the rest should work.


scene = GameLogic.getCurrentScene()
objList = scene.objects
object = objList["object"]
getproperty = object.property
#you can only read a property using the above, to set it use "object.property = x" , to read "x = #object.property"

I tried using object.property before and it said that the object didn’t have that attribute. HG1’s code does work, and thanks for posting that.

object.property is deprecated since 2.49

the current method since 2.49 is dictionary access:
object[“propname”]
or
object.get(“objectName”)

The code is working. But it is only working with properties that assigned to the object where the script is running. You haven’t wrote that you want to change the property of an other object with the script.
Property.blend (422 KB)

i do apologise! i assumed that as getattr and setattr are now deprecated, that object.propname was the newest method, especially considering it is logical, which the new api is; controller.activate, bge.logic (not stupid case-sensitive GameLogic)
i am also using the new method now.