Hi dear all. I’ve created a psychopy experiment in the builder view. it contains an excel file and in the excel file, there are three columns containing auditory rhythms. Then I created three routines each of which containing one column of the excel file.
At the moment when I run it, it presents audio samples in the order they are in the excel file, I mean the first column, then the second, and then the third column. I want to include a code in my builder view that makes these samples to be presented at random. Do anyone knows how can I write the code?
I’m a beginner at programming and I appreciate detailed guidance.
Thanks in advance.
I attach my psyexp and xlsx file here. I’m not sure if it’s better to have three routines each containing one column or having one routine containing three sound components and each containing one column. I just know that in each loop I need to randomize three columns but I don’t know how!
auditorySamples.xlsx (8.1 KB) SeqAud.psyexp (9.5 KB)
You just need a single routine, surrounded by a loop that has an nReps
of 3. Insert a code component (from the “custom” component panel), and put something like this in the “Begin routine” tab:
# only at the start, get the sound file names and randomise them:
if your_loop_name.thisN == 0:
sound_values = [column_1_name, column_2_name, column_3_name]
shuffle(sound_values)
# select the sound for this iteration:
current_sound = sound_values[your_loop_name.thisN]
# record it in the data:
thisExp.addData('current_sound', current_sound)
Then in your sound component, put this in the “sound” field:
$current_sound