Screen stuck due to a code component

URL of experiment: https://pavlovia.org/run/Tingyu/condition-1/html/
Description of the problem:
Hi all,

I have a code component which enables participants to replay sounds by clicking buttons on the screen. It runs well offline. I chose Auto > JS code type, but screen stuck online and the error message is: core.wait is not a function.

My code is:
if (mouse.isPressedIn(polygon_8)) {
sound_8.play();
core.wait(sound_8.getDuration());
sound_8.stop();
}

I cannot figure out which function to use online, thus help would be appreciated!
Thanks!
-Tingyu

Hello,

core.wait is PsychoPy function, not a PsychoJS function, see here.

Best wishes Jens

Thanks Jens! Is there any alternative function that I can use instead of core.wait?

You could put the sound into a separate feedback routine.

Alternatively, start the sound and save the value of t and then check if t > savedT+x and savedT > 0 then stop the sound and reset savedT to 0

x should be the known length of sound 8

Thanks Wakefield! I’ll try and hope it can resolve my problem.