Hello, I’m writing a python script to play a sound every time i press a button
from bge import logic import aud cont = logic.getCurrentController() scene = logic.getCurrentScene() keys = cont.sensors["keys"] SPACE = keys.getKeyStatus(32) device = aud.device() SFX = logic.expandPath('//Sounds/') sfx_sound = SFX+"sound"+".wav" if SPACE == 1: beep = aud.Factory.file(sfx_sound) device.play(beep)
It works fine, but if I keep mashing the button it creates new instances of the same sound, that end up overlapping with each other.
I want the sound to stop and start over again when i press the button. Is there any way to do this?
Thanks in advance.