python issue

hi. i feel like an idiot :smiley: but i want to acces property from player and give the info of it to an enemy… that property is PlayerAlive.

so i do this:


#defining the objects 

import GameLogic 
scene = GameLogic.getCurrentScene() 
cont = GameLogic.getCurrentController() 
own = cont.owner 
player = ["OBDefault"] 
 
############################################################# 
#defining AI variables 
 
PlayerAlive = player["Alive"] 
SeePlayer = own["SeePlayer"] 
PlayerNear = own["PlayerNear"] 
SeeYou = own["SeeYou"] 

but console print this:


Python script error from controller "AI#CONTR#1":
Traceback (most recent call last):
  File "AI", line 12, in <module>
TypeError: list indices must be integers, not str

and on line 12. is this: PlayerAlive = player[“Alive”]

i dont understand this please help

player is a list just containing the string “OBDefault”.

I think you meant it should be a reference to an KX_GameObject.

Maybe this is what you want:


GameLogic.getCurrentScene()["OBDefault"]

i thin this is it but the console will print this…


Python script error from controller "AI#CONTR#1":
Traceback (most recent call last):
  File "AI", line 7, in <module>
TypeError: 'KX_Scene' object is unsubscriptable

bumping :smiley: