I am attempting to use Builder to create an experiment which uses sound objects.
The experiment runs correctly locally from the psyexp file. The problem arises when I attempt to export it to JavaScript, either for piloting locally, or for upload to Pavlovia. The generated javascript file includes two extraneous curly brackets, which, unsurprisingly, break functionality.
Here’s a longish code snippet for context. This is all code that is being auto-generated by Builder. The only change I’ve made here is to add the comments next to the problematic brackets, and add space above and below for contrast:
// if confidenceSlider_2 is active this frame...
if (confidenceSlider_2.status === PsychoJS.Status.STARTED) {
}
if (SoundA_2.status === STARTED) {
SoundA_2.isPlaying = true;
if (t >= (SoundA_2.getDuration() + SoundA_2.tStart)) {
SoundA_2.isFinished = true;
}
}
// start/stop SoundA_2
SoundA_2.play(); // start the sound (it finishes automatically)
SoundA_2.status = PsychoJS.Status.STARTED;
} //THIS BRACKET IS A PROBLEM!
if (SoundA_2.status === PsychoJS.Status.STARTED && Boolean(false) || SoundA_2.isFinished) {
// keep track of stop time/frame for later
SoundA_2.tStop = t; // not accounting for scr refresh
SoundA_2.frameNStop = frameN; // exact frame index
// update status
SoundA_2.status = PsychoJS.Status.FINISHED;
// stop playback
SoundA_2.stop();
}
if (SoundB_2.status === STARTED) {
SoundB_2.isPlaying = true;
if (t >= (SoundB_2.getDuration() + SoundB_2.tStart)) {
SoundB_2.isFinished = true;
}
}
// start/stop SoundB_2
SoundB_2.play(); // start the sound (it finishes automatically)
SoundB_2.status = PsychoJS.Status.STARTED;
} // THIS BRACKET IS ALSO A PROBLEM!
if (SoundB_2.status === PsychoJS.Status.STARTED && Boolean(false) || SoundB_2.isFinished) {
// keep track of stop time/frame for later
SoundB_2.tStop = t; // not accounting for scr refresh
SoundB_2.frameNStop = frameN; // exact frame index
// update status
SoundB_2.status = PsychoJS.Status.FINISHED;
// stop playback
SoundB_2.stop();
}
// *mousePlay_2* updates
When you attempt to run this code, it doesn’t work, since the curly brackets close off the function for the block way too early. The specific error being generated is “illegal return”, since a “return” statment much lower down is now outside of any function. But that’s a symptom - the problem is these two curly brackets being dropped into the code for no apparent reason.
There IS some manual code in this project, but it’s entirely cosmetic - opacity and the like. And again - these brackets are in the auto-generated portion of the code, not the manual section at the end of the function.
I can go in and manually delete the brackets, but I have to do it every time I make any updates to the code, and it also means I can’t auto-synch with Pavlovia, because that regenerates the JS with the bad brackets.
What could be causing this?