Python List: get

get(val)
  • Returns a value from a BGE python list.
  • Returns None if value isn't found.

Return Type:

  • Same as list.  Boolean or string or integer or etc.
val:
  • name of the value to be returned.

 

get(val, default)
  • Returns a value from a BGE python list.
  • Returns the default value if val isn't found.

Return Type:

  • Same as list.  Boolean or string or integer or etc.
val:
  • name of the value to be returned.
default:
  • default value to be returned if named value isn't found.
Sample Code

################## get a value from the list  

# import bge
import bge

# get the current scene
scene = bge.logic.getCurrentScene()

# get list of objects in scene
objList = scene.objects

# get Cube_1 from objList.  No default value
obj = objList.get("Cube_1")

Sample Code

################## get a value from the list. Return default if it isn't found.

# import bge
import bge

# get the current scene
scene = bge.logic.getCurrentScene()

# get list of objects in scene
objList = scene.objects

# get Cube_1 from objList.  Use default value if not found
obj = objList.get("Cube_1", "Object not found")