Python List: index

index(val)
  • Returns the index position of a value in the list.

Return Type:

  • integer
  • 0 = 1st position
  • 1 = 2nd position
  • 2 = 3rd position
  • etc.
val:
  • the value.
Sample Code

################## get the position of a value from list

# import bge
import bge

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

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

# get the object from the list
obj = objList.get("Cube_1")

# get object position from objList.
pos = objList.index(obj)