Keyboard error - double ticks

Hey folks,
I’ve a problem with my current game project “NAFS-Race”.
Every time I use Keyboard input, in combination with Phyton-code, the code will be executed twice.

The following picture shows my complete setup. The key “B” was only pressed one time, but the code was executed twice.

Settings like “Level” or “Tap” have no effect.

In fact there is one excecution(/sended message) while pressing the key and one while releasing the key.

This is logical, but how to prevent it?
(I solved it in another case with another state and a delay sensor, but this is to complex, I think)


Thanks,
Flo :slight_smile:

This is normal. Check Double execution of a python controller

Have you tried setting both actuators to Tap (not just one)? It says your sending the message to nothing, maybe name the objects? Also, just a tip, it should be ‘Car Bought’, not buyed. :slight_smile: Your game looks good, by the way. :slight_smile:

I tried to recreate the problem without Python, but couldn’t. So I assume it’s your code.
This only makes the property 1.




Do you want the key to only work once per tap for a certain amount of time?

if message=B--------------and
if X=0 ------------------------/ ----------------------------------X=1

if X=1-------------------------Python
---------------------------and--------------------------------X=0

This only triggers once :slight_smile:

if the message comes in and you are “ready” do the thing, then reset,

this can be done as a for loop instead as well

Attachments

CodeItAllWeapon.blend (491 KB)

Thanks for your reply guys! :slight_smile:

@RossBlenderArt: Thank you for the wrong spelling tip (it was wrong in the whole game and code :smiley: [approx. 20 times]) and thank you for the positive message about my game.

@BluePrintRandom: I choose a more friendly way for my, by integrating it in python.

@Monster: Thanks for the link to your code-examples. I’d choose the following code and it works fine within my current code.

def onePositive(cont):for sensor in cont.sensors:

[INDENT=2] if sensor.positive:
[/INDENT]
[INDENT=3] return True
[/INDENT]

def Buy(cont):if onePositive(cont):
[INDENT=2] return
[/INDENT]
print(“Car bought!”)

Flo