Python Help

Im trying to make a script where it changes the action so that I dont have 8 logic bricks connected to my sensor. My question is how do u change the action? Here is my script and im using 2.55:

import bge
cont = bge.logic.getCurrentController()
 
#sensors
sensW = cont.sensors["W"]
sensS = cont.sensors["S"]
sensA = cont.sensors["A"]
sensD = cont.sensors["D"]
 
#actuators
actu = cont.actuators["Action"].action["F/ B"] #this line doesnt work
 
if sensW.positive:
    cont.activate(actu)

Thanks

If I understand your code properly, you should change

actu = cont.actuators["Action"].action["F/ B"]

to

actu = cont.actuators["Action"].action = "F/ B"

I’m understanding that “Action” is the name of your action actuator and “F/ B” is the name of the action animation that you want the actuator to use.

Yes, your right but now in the consle it says: ValueError ‘‘F/ B’’ not in this python contollers actuator list

Oh sorry… I don’t know how I made that mistake. There are two equivalency statements in one line there. This should do what you’re wanting:

actu = cont.actuators["Action"]
actu.action = "F/ B"

Thank you it worked! :smiley: Now I know that you cant have two equivalency’s on one line