Game Object: get

get(property, default)
  • get the value of the named Property

Return Type:

  • Property exists:  The value of the property
  • Property doesn't exist and no default value set:  None
  • Property doesn't exist but default value was set:  default value

property:

  • Property to look for.
  • Type:  string
default:
  • default value to return if the property doesn't exist
  • Type:  string/integer/float/bool
Sample Code

################## get the named property value on the game object
  

# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# property to get
property = "Health"

# default value if Health not found
default = 100

# get the property value
obj.get(property, default)