Stuck on the "initialising the experiment" page

URL of experiment: Sign in · GitLab

Description of the problem: This is a typical question, but I haven’t solved it. I posted my PsychoPy Builder study to Pavlovia, and when I go to execute the pilot, it’s just a blank screen written ‘initializing the experiment…’ But there is a difference with other I guess because there is also a sound variable problem.
import sound


When the experiment goes online, there’s a problem with js codes. I’m getting an error in the form of “SyntaxError: redeclaration of const sound” for the sound I’ve specified. Does anyone have any suggestion for a solution? For example, how else can I name a sound variable?


It looks like you’re trying to create a sound object inside a code component. That just doesn’t work on Pavlovia right now. Create a sound component in the builder, or better yet, create two separate sound components for your two sounds, and then use your code component to actually play the sound when appropriate.

I’m kind of new at Psychopy, so I don’t quite understand what you’re trying to suggest. How can I use my “code component to actually play the sound when appropriate.” I created two individual sound components, but I couldn’t figure out exactly how the code should be in this situation.

Thank you.

No worries! So the code you pasted above is designed to check whether the key response was accurate or not and change the sound accordingly. Now you have two different sound components, let’s call them CorrSound and ErrSound (I don’t know what you actually called them, but I think you get the idea). Make sure each sound component is set in the builder to start on “condition” and leave the start time blank.

Then, in the each frame tab of your Feedback trial:

if (KeyExp.corr){
    ErrSound.status = PsychoJS.Status.FINISHED; // This is just so it doesn't hold up on ending the trial because this sound didn't play.
    if (CorrSound.status === PsychoJS.Status.NOT_STARTED) {
      CorrSound.tStart = t;  
      CorrSound.frameNStart = frameN; 
      psychoJS.window.callOnFlip(function(){; });  
      CorrSound.status = PsychoJS.Status.STARTED;
    if (t >= (CorrSound.getDuration() + CorrSound.tStart) && CorrSound.status === PsychoJS.Status.STARTED) {
      CorrSound.status = PsychoJS.Status.FINISHED;
} else {
    CorrSound.status = PsychoJS.Status.FINISHED;
    if (ErrSound.status === PsychoJS.Status.NOT_STARTED) {
      ErrSound.tStart = t;  
      ErrSound.frameNStart = frameN; 
      psychoJS.window.callOnFlip(function(){; });  
      ErrSound.status = PsychoJS.Status.STARTED;
    if (t >= (ErrSound.getDuration() + ErrSound.tStart)  && ErrSound.status === PsychoJS.Status.STARTED) {
      ErrSound.status = PsychoJS.Status.FINISHED;

This a slightly more advanced way of doing it than you strictly need, but it should make it start the sound, play it, end it at the right time, and not interfere with ending the trial otherwise.

Thank you very much Jonathan!

But there is an error occurred. I tried editing it in a few ways, but I still couldn’t fix it.

Oh interesting. It seems you cannot leave the start time blank. Have it start at, say, 1s. It will be overridden by the code component anyway.

Now I hear the sound of beep uninterrupted. Do you think there’s a mistake in the changes I’ve made?

That’s odd. It shouldn’t try to play the sound if it’s already playing, but it sounds like that’s exactly what it’s doing. I’ll make a copy of your experiment and have a look.

1 Like

All right, I got it working for me on Pavlovia. You just need to make a couple of changes in the builder to CorrSound and ErrSound. Here’s what Corrsound now looks like for me:

Note that I have set it to start based on time at .2 seconds. This does not actually occur because the code component overrides it. Also, make sure you set the sound file to be constant, and set it to the filename of the sound you want to play.

As a general note, you can’t create sounds that are just tones online (e.g., with “A” in the sound field). They all need to be files.

I appreciate your efforts and help, it’s working right now!