Mousepress for playing sound component works, but sound 'piles up' with multiple presses

Hi guys,

I am building an experiment (version 2.10, standalone) where participants must create a signal by pressing a mouse button. It’s one of these things that work fine locally, but not online.

The critical part is that they can test whether the apparatus works: they can try it out and click multiple times in the test round. So, basically, they click --> sound is played, they release --> sound stops, click again and sound is played again, etc.

When I try this in my pilot online, the sound seems to ‘pile up’: it sounds as though multiple instances of the sound get played at the same time.

Here’s my JS code:

if ((! (testsound.status === STARTED))) {
if (mouse_2.getPressed()[0]) {
testsound.play();
}
} else {
if ((testsound.status === STARTED)) {
if ((! mouse_2.getPressed()[0])) {
testsound.stop();
}
}
}

The sound component is set to ‘set every frame’, so for every frame, it checks whether the mouse is being clicked or not.

I’m not sure what’s causing this; like i said, it worked locally before… I feel like it needs something to clear the presses, but clearEvent() does not work.

-Sabine

Hi @Sabinosaurus, thanks for flagging, could you send me a link to your repo so I can take a closer look? Thanks, s.

Hi @Sabinosaurus, thanks for adding my account to your repo, could you give me developer level permissions so I can access the code? Cheers, x

Sorry @sotiri, fixed it now

Hi @Sabinosaurus, great thanks :blush: Cool study! It looks like your desktop project is using the latest PsychoPy, but the HTML export is set to an older, pre 2020 version. You can choose which version to target for online use via the settings dialog below,

I have staged an updated support fork, does that work more or less as expected? x

Hey, sorry for the late response! That is actually odd; I created the project initially in 2015, but updated my psychopy standalone version recently in order to run this experiment online.

It didn’t fix the issue unfortunately… In the end I decided to adjust the task a bit so that I no longer have to deal with the issue.

Thanks for reaching out though!

No problem, happy coding :sunny: