Randomly sampling from two groups and presenting all sampled stimuli in random order

Description of the problem:

Because I’ve run into problems getting custom code components which do this to work on Pavlovia, I was wondering if there is a way to randomly sample stimuli from two different groups, and present them, one after another, in a loop while randomizing the order of the presentation.

In particular, I would like to sample two stimuli from one list (e.g., sampling two pictures of faces); two stimuli from another list (e.g., two pictures of plants) and present these four stimuli in a randomized order. I imagine there must be a way to do this in PsychoPy that also works in Pavlovia. I’ve attempted custom code components using Python and Javascript, but I can’t seem to get them working in PsychoJS. My experiment deals with sampling audio according to whether music is in a major or minor key.

The following code works in Python but not PsychoJS:

This code seems to work in JS but runs into a problem when assigning the randomly sampled pieces to a soundfile component.

Any suggestions/insights are much appreciated.