URL of experiment:
Description of the problem:
I set a button to replay a sound stimuli using the following code in RoutineEachFrame in JS. “sound_2_answer_c” is the name of the sound stimuli.
I used the same method in another experiment and it worked well. However, some creaky noises occurred when I clicked the button in this experiment. If I don’t release the left button of my mouse, the noise will not disappear, and after I release the left button, it stops and the sound stimuli replays. I am not sure if this has anything to do with the loop, because the other experiment where it functions well has no repetition.
if (button_2_c.status === PsychoJS.Status.STARTED) {
// check whether button_2_c has been pressed
if (button_2_c.isClicked) {sound_2_answer_c.play();
if (!button_2_c.wasClicked) {
// store time of first click
button_2_c.timesOn.push(button_2_c.clock.getTime());
// store time clicked until
button_2_c.timesOff.push(button_2_c.clock.getTime());
} else {
// update time clicked until;
button_2_c.timesOff[button_2_c.timesOff.length - 1] = button_2_c.clock.getTime();
}
if (!button_2_c.wasClicked) {
sound_2_answer_c.play();
}
// if button_2_c is still clicked next frame, it is not a new click
button_2_c.wasClicked = true;
} else {
// if button_2_c is clicked next frame, it is a new click
button_2_c.wasClicked = false
}
} else {
// keep clock at 0 if button_2_c hasn't started / has finished
button_2_c.clock.reset();
// if button_2_c is clicked next frame, it is a new click
button_2_c.wasClicked = false;
}```