Hey everyone. I am new to python and bge and am trying to write a simple script to move a block within bge using python. The block moves to the “a” (left button) and “d” (right button) keyboard buttons at the beginning but after one of the direction buttons is pressed, the other direction can only bring the block to a halt and not continue to move the block in the other direction. It might just be easier to take a look at the attached code (btw i havnt posted since they updated the website. is there a way to attach files anymore?).
import PhysicsConstraints
import GameLogic
# get the controller the script it attached to
controller = GameLogic.getCurrentController()
# get a list of sensors connected to the python controller
senList = controller.sensors
# get a list of actuators connected to the python controller
actList = controller.actuators
# get the keyboard sensor named leftsensor
l = senList["leftsensor"]
# get the keyboard sensor named rightsensor
r = senList["rightsensor"]
# get the motion actuator named moveleft
ml = actList["moveleft"]
# get the motion actuator named moveright
mr = actList["moveright"]
# l.positive == True means a key was pressed
# l.positive == False means a key was released
# Run indented code on when a key is pressed
if l.positive == True:
# turn the motion actuator on
controller.activate(ml)
# Run indented code on when d key is pressed
if r.positive == True:
# turn the motion actuator on
controller.activate(mr)
Thanks a lot. I greatly appreciate the help.
amartin7211