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'
else:
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.
Ok I think I am pretty close, but I am still not able to make this work.
So when I set the conditions for the experiment loop as the master csv file, I get the following error
UnboundLocalError: local variable ‘trialList’ referenced before assignment
I can make the program work by creating a set of nested loops where I have a csv that refers to a specific csv of stimuli for each age, and then the stimuli component calls up the filename from the column of filenames in the csv, but with this design (which seems less effcient), it is not actually limiting the stimuli to the correct useRows specification, but pulling a random one from the list.
How can I tell the program to reference a row of stimuli files in the component rather than a column? (I tried $useRows that didn’t work either).
Update 2:
I was able to create a version of the experiment that successfully presented the loop/didn’t crash/pulled stimuli, but it is still not responding to useRows correctly (i.e. stimuli not conditional, it’s just fully random) and I think this is because I need to tell psychopy to store the response from ageResp in order to relate it to useRows. I think!
What’s the code for storing a response? I think if I add that to the ageAsk routine, the if then statements should work correctly in the following routine.