So I have a camera for my FPS and I am writing a script for it to look at and handle the different items and weapons on the map to alter properties appropriately.
I am trying to write it so that if I press R while looking at something with a certain property it will change my “left hand” property to reflect I am not holding something.
The layout is:
some stuffs...
sens = cont.sensors['mouseSelect']
keyboard = bge.logic.keyboard
equip = bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.RKEY]
some more stuffs....
if equip:
do the rest of it
The problem is, the equip never triggers true, and never enters that if. I have no console errors with this setup, and debug print statements confirm it reaches right to that point, then skips the if.
I also tested it by instead of if equip:, it is if sens.positive:, and this works, confirming that the script works without the equip key trigger attempt.
So any ideas what I am failing to see here?
If I also wanted to make it an and, in C I would say if(equip && sens), how would I make such an && statement in python? Forgive my noobiness on this :o.
I suggest you use an keyboard sensor to directly sense the key you want. You can check the sensor status with.positive without to worry what key is sensed and if it is a leyboard sensor at all. This is simple and it separates the operations you want to perform from the events you want to sense.