I’m following a tutorial from youtube on python scripting for the blender game engine. I’ve checked the code and it is identical to that in the tutorial, but I am getting the error “AttributeError: ‘module’ object has no attribute ‘getKeyboard’” in the console when I start the physics (“p”). The cube does not respond to the up arrow, either. Posting the blend file and the python script. I suspect this is a problem with the bge python not being aware of some path name or something, but I am not sure. The script is in a sub-folder called “Python” under the project folder where the blend file resides.
Here is the content of the py file:
Make sure to set up an Always sensor and a control
cont = bge.logic.getCurrentController()
cubeobject = cont.owner
# Get the scene for the mouse and other things scene = bge.logic.getCurrentScene() # Get a keyboard keyboard = bge.logic.getKeyboard()
First check for a keyboard event and a specific key.
# Now check keyboard input (Input Status) if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.UPPARROWKEY]: cubeobject.localPosition.y += 1.0
Here is the console output:
Blender Game Engine Started
Python script error - object ‘Cube’, controller ‘Python’:
Traceback (most recent call last):
File “keyboard_input”, line 23, in <module>
File “keyboard_input”, line 13, in main
AttributeError: ‘module’ object has no attribute ‘getKeyboard’
The blend file is attached.
keyboard_input_learning.blend (486 KB)