Hi Michael,
Thanks for your quick response! I’ve actually tried a number of different things, most of which worked in PsychoPy but not online unfortunately.
Over 4 practice trials I am presenting participants audio files of 2 pieces written in a major key and 2 pieces written in a minor key in a randomized order. To do this, I sample two pieces from a list of major pieces and two pieces from a list of minor pieces. I then concatenate the lists together and shuffle them.
Once I have shuffled the new list of pieces, I assign each index of the new list to a variable (e.g., pracPiece1). These variables are then used as values in an audio component in builder.
Here is my custom code component to randomly sample the 4 pieces from two lists. I’ve modified it a little by changing the number of files, as well as the names to make it easier to read and less redundant. This code works in PsychoPy but not Pavlovia.
#This code prepares a CSV which randomizes 2 major and 2 minor pieces for the practice trials.
#Make list of major pieces
major = ("testMusic/Major1.wav",
"testMusic/Major2.wav",
"testMusic/Major3.wav",
"testMusic/Major4.wav")
#Make list of minor pieces
minor = ("testMusic/Minor1.wav",
"testMusic/Minor2.wav",
"testMusic/Minor3.wav",
"testMusic/Minor4.wav")
#Randomly sample two pieces from each list
major = np.random.choice(major, 2, replace = False)
minor = np.random.choice(minor, 2, replace = False)
##--Other attempts from random module--##
#major = random.sample(major, 2)
#minor = random.sample(minor, 2)
#concatenate dataframes
frames = major + minor
#sample 4 pieces: half major, half minor
## other attempt with random module: pracData = random.sample(frames, 4)
pracData = np.random.shuffle(frames)
#pracData = frames
#assign pieces to variables
pracPiece1 = pracData[0]
pracPiece2 = pracData[1]
pracPiece3 = pracData[2]
pracPiece4 = pracData[3]
I’ve tried changing where in the code component I put this code, and have tried importing numpy.random as well as the random sample function from the random module.
My builder view looks like this, where the randomizer code is in one routine and the presentation of the four pieces in separate routines. I have also tried this format using a loop in the builder view.
The piece routines look like this:
I’m kind of stuck for what to do. I’ve tried relying less on external modules and tried a very basic approach to see if this was more compatible with javascript. Any help/input would be greatly appreciated. The error pavlovia usually throws are :
- Some component is missing (when using the random module)
- np (or numpy) is not defined when using the numpy module–I thought this one may work because psychopy uses numpy.
Any help would be appreciated greatly!