Conditonal Randomized Stimuli Based on Age Range

OS (e.g. Win10): MacOS Catalina
PsychoPy version (e.g. 1.84.x): 2021.2.3
Standard Standalone? (y/n) If not then what?:Yes
What are you trying to achieve?:
I have a directory of popular songs – 50 for each year (1940-2023). I want to present 30 randomized songs from the range of years when the participant was 7-19 years old, based on the birth year input at the beginning of the experiment. Based on this input, the program will need to randomly select 30 from the possible 500 stimuli within that range.

I am trying to find the best way to set up my csv files. I could put audio filenames in separate csvs (1 for each year), or I could create one giant csv with corresponding rows or columns for the files by year. I am not sure which route to take - I will need to make sure the loop condition can use the input from the age range to limit what part of the stimuli directory it is looking at. I have an image of my potential experiment flow attached. I think what needs to happen is the age input occurs before the nested trial loop, and I have code in the next routine (codeInit) to generate the calculated range. It seems I would take the variable of that range and plug it into the condition(?) or selected rows(?) in the trial loop options, but I am not sure exactly what would work.

Another potential solution would be to create a csv file with all 500 possible songs for each corresponding birth year, in which case I would need to equate the birth year input with its corresponding csv as a condition. I am not sure if this is simpler.

Thanks in advance!

I would recommend using selected rows.

For example:

if age > 50:
     useRows = '0:30'
elif age > 40:
     useRows = '30:60'
elif age > 30:
     useRows = '60:90'
     useRows = '90:120'

This makes sense. Two questions

  • I put this in a code component inside or outside the loop? What would I put in the loop condition? It won’t accept lines of code

As far as presenting the stimuli, I think what I would do is put a csv file name (i.e. 2001.csv) in each row that corresponds to a list of stimuli for that year. The Year CSVs will contain one column each called stimFile that have the list of filenames. I suspect that when the program reads the correct year CSVs as determined by the age limitation, it should grab stimFiles from each corresponding year? Does that sound right?

Thank you so much!

Code for useRows would need to be in a code component before the loop, then put $useRows as the selected rows in the loop.

However, if you are suggesting one CSV file per year, then the code component determines the file, not the rows (which is easier to understand, but slightly less efficient)

Also, before the code, you’d need useRows = “” if you wanted it to work online.