how to call an object property on a If?

Hi, i was making a script that includes a property on it. At the moment of call the property, blender script has given me a error, that says:
animations Python script error - object bruno skelleton, controller ‘Python’: File “animations”, line 72, in <module> NameError: name o is not defined …
and the part of the script is this:
if o[“frame”]==172.0:
Cube.enableDynamics()

how is the correct way to call an object property on an if sequence in python? Do i have to define the property on my vars?? if so, how can i define it?

you need to find out what the controller is then find the owner of the controller.


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

Then properties can be changed using own[“property”].

Another way is to select an object from the scene.


from bge import logic
scene = logic.getCurrentScene()

Then you can get the property using scene.objects[“Object”][“property”]

the strange thing is, YESTERDAY THAT SCRIPT JUST WORK FINE!! AND NOW IS GIVING ME THIS ERROR!!! WTF???

here’s the full script

import bge
g = bge.logic
co = g.getCurrentController()
scene = g.getCurrentScene()

####DEFINO VARIABLES ######

sensor = co.sensors[“Keyboard”]
act = co.actuators[“Action”]

WKEY = sensor.getKeyStatus(119)
SPACEKEY = sensor.getKeyStatus(32)
HKEY = sensor.getKeyStatus(104)

ray_cover = co.sensors[“Ray”]

##########CAMINAR##############

if WKEY==1 and SPACEKEY==0 and HKEY==0:
act.action = “caminar”
act.frameStart =1.0
act.frameEnd = 25.0
act.blendIn = 2
act.mode = 4
act.priority = 2
co.activate(“Action”)

########PARADO###############

if WKEY==0 and SPACEKEY==0 and HKEY==0:
act.action = “parado”
act.frameStart = 1.0
act.frameEnd = 250.0
act.blendIn = 10
act.mode=4
act.priority = 2
co.activate(“Action”)

#############CUBRIRSE###################

if ray_cover.positive and HKEY==1 and SPACEKEY==0 and WKEY==0:
act.action = “cubrirse”
act.frameStart = 1.0
act.frameEnd = 250.0
act.blendIn = 10
act.mode=4
act.priority = 2
co.activate(“Action”)

##########ESCALAR MUROS###########################

Cube=scene.objects[“Cube”]
ray_obstaculos=Cube.sensors[“obs”]
camara_animaciones = scene.objects[“camara anim”]
camara = scene.objects[“Camera”]

if ray_obstaculos.positive and SPACEKEY==1 and WKEY==0 and HKEY==0:

Cube.applyMovement((0.0, 1, 6), True)
Cube.suspendDynamics()
act.action = "trepar"
act.frameStart = 1.0
act.frameEnd = 172.0
act.blendIn  = 0.0
act.mode=2
act.priority = 2
co.activate("Action")
o["escalo"]=True 

i have a Keybord sensor with allKeys activated connected to the python controller and also connected with an Action actuators, where i play all the animations i define upthere …
I don’t know what’s wrong with this script.

You haven’t defined “o”. You can do that like this:


...
co = g.getCurrentController()
scene = g.getCurrentScene()
o = co.owner
...

You should use conventional terms for the names of certain variables such as the controller and owner.
(cont = logic.getCurrentController, own = cont.owner/obj = cont.owner). Most people use those terms, though it is not necessary.
instead of “g = bge.logic”, should be “from bge import logic as g”

OOOOOH! you’re right man!!! that could be a NICE IDEA!!! :))