hi i want to write a script for a game that plays actions when a key is pressed just like the action actuator would but i do not know the syntax to do so, can anyone help me
I’m not sure how to do this without an action actuator but you can certainly control an action actuator via python. Perhaps be more specific about what version of Blender your looking for help with and what exactly you mean.
thanks for the help that will be really useful
btw i use blender 2.63
In blender 2.63, I think the module is called bge. You want to get the controller that the script is running on and from there you can get any actuator by name, which it is connected with it. This is usually all that is needed although there are other ways. You can use print(dir( <item of interest>)) to show available option, or check the python api.
What about a setup like this. (shown in the image below).
Create a game scene property called play_action.
Instead of using an Always->And->Action(play) series use a Property-And->Action(play) with the property linked to the above mentioned game property.
Have another keyboard sensor change that Property from False to True when pressed.
Remember, python code is going to run slower than the SCA (Sensors, Controllers, Actuators) so it is best practice to try and solve the problem using the logic bricks first. In your case, it may be possible to write a python keyboard scanner and then set the play_action game property to True in your python script but you may encounter FPS drop by solving the problem that way.