Stimuli change in PsychoPy but not in Pavlovia

URL of experiment: Pavlovia

Description of the problem:
When I run locally with PsychoPy, the audio stimulus files change from trial to trial, as is expected. But when I run in Pavlovia, the same audio file plays on all trials.

I defined a sound object in builder, named “stim”, and it’s Sound is “$wavfile”, a variable that I set in Begin Routine, like this:

Python:
wavfile = stimdir + thisTrial[‘stimfile’] + “.wav”

JS:
wavfile = stimfile + “.wav”;

“stimfile” is the name of the audio file, and I know that it is changing randomly every trial because when I export it with:

trials.addData(“wavfile”, wavfile);

I can see that wavfile changes from trial to trial. So it seems like the sound object “stim” is not updating with $wavfile. I tried changing it for example:

stim.Sound(wavfile);

but this gives an error, and I can’t figure out the JS syntax to change the audio file for the sound object.

Any help would be much appreciated.

To get the sound stimuli to change each trial, I had to define a new sound object in a “Begin Routine” block:

stim = new sound.Sound({
win: psychoJS.window,
value: wavfile,
secs: 1.0,
});

This works, but I wonder if there is an easier way of doing this.