Defining a loop at the start of the experiment

Is it possible to define a loop at the beginning of an experiment? I am using 3 identical routine (all called stimuli); however they are each surrounded by a separate loop. When the experiment starts, a line of code chooses which of these 3 routines appears (each loop reads from a different csv file)

The code component of the stimuli routine has a line that says if MyCount=3 end the loop, which shows up in each of the 3 stimuli routines. However, the experiment crashes if the first or second routines are chosen (error: name of loop is not defined) because the experiment technically hasn’t seen each name of the loop. In other words, the experiment only works if the last of the 3 identical routines is chosen first. Does anyone have any recommendations on keeping the same routine (need one routine for analysis purposes) while also making sure the loops are defined at the start of the experiment?

Hello,

If you only want to show one of the three sets of stimuli, there is no need to use three identical routines with different condition files. Just make the condition file a variable that you set before you loop over your stimuli.

if cond == 1:
    condFile = "condition1.xlsx"
elif cond == 2:
    condFile = "condition2.xlsx"
elif cond == 3:
    condFile = "condition3.xlsx"

grafik

Or you could put all the stimuli in one condition file and use the Selected rows parameter of the loop to display only selected rows.

Or you could set the nReps-parameter to 0 using a variable in case you don’t want to run the loop.

Best wishes Jens

Update: above solution (using the condition file as a variable) did exactly what i needed worked! Thank you!

Originally, I was using 3 identical routine because of them had a different variable in the nReps section which is how they were randomly chosen at the start of each loop.

Follow up, if I decided to use one xlsx file, would it possible to also specify the rows in this if statement (ex: if cond ==1: only read rows 1-12 in the condition file). In other words, the xlsx file would contain 3 different categories of images.

I had originally done this by defining a variable in the begin experiment tab (ex: TargetRows=‘1:12’) and then entering this variable in the selected rows section of the loop. However, I don’t believe this will work since i have 3 different categories of a variables within the rows of each excel file.