I have two routines A and B, which I want to loop through in a predefined order that is not sequential or alternating, such as AAABABBAABBBA. A is a picture task and B is a video task. This is the setup in Builder view:
The conditions file for the outer loop looks like this:
chooseRoutine
chooseConditions
A
filepath/conditions.xlsx
A
filepath/conditions.xlsx
A
filepath/conditions.xlsx
B
filepath/conditions.xlsx
A
filepath/conditions.xlsx
B
filepath/conditions.xlsx
etc
etc
The conditions sheets for loopA and loopB are set as $chooseConditions.
I have this code component in Begin Routine for taskA and taskB (I’m not too familiar with Python/coding in general, so I used ChatGPT for this):
# Get the routine type and conditions file from the current row
routine_type = outerLoop.thisTrial['chooseRoutine']
conditions_file = outerLoop.thisTrial['chooseConditions']
# Set the conditions file for the inner loop based on the routine type
if routine_type == 'A':
loopA.setConditions(conditions_file)
elif routine_type == 'B':
loopB.setConditions(conditions_file)
I get this error when I try to run the experiment:
loopA.setConditions(conditions_file)
AttributeError: 'TrialHandler' object has no attribute 'setConditions'
################ Experiment ended with exit code 1 [pid:66780] #################
Please let me know if you can see any way to fix this! Thank you
ChatGPT isn’t very good at working with PsychoPy Builder.
If outerloop is pointing at a spreadsheet then chooseRoutine will already hold the current value from that column.
You can’t set a conditions file for a loop after it has started. To do that you would need a routine that runs within outerloop but before loopA and loopB.
How many rows does conditions.xlsx have?
The following doesn’t need any code components but might not produce the result you actually want.
Give your outer loop spreadsheet three columns, chooseA, chooseB and conditions_file:
For the inner and middle loops, I set the Num. repeats to chooseA / chooseB. The inner loops have conditions set as $conditions_file.
This setup does correctly run through the tasks in the order specified by the spreadsheet. However, taskA is incorrectly skipped when preceded by taskB. If I have two taskAs consecutively, the second will run correctly but the first will be skipped. The instructions/feedback appear correctly always. I have checked and it’s not an issue with the stimuli filepaths.