Routine won't end after specified number of Loops

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2021.1.4
What are you trying to achieve?:

My experiment shows participants an image and has them interact with the image. When they have finished, they press enter and a new image is shown. Each image constitutes one trial, and I have the image names written in a list in the code components for each routine (phase of the experiment). In the experiment, I have a routine with 30 reps (each rep is one trial). After 30 reps, the routine should end and the next routine should start. However, the routine just stays stuck on the 30th trial and doesn’t advance to the next routine.

What did you try to make it work?:

I specified 30 reps in the loop properties, and when that didn’t work I added the following code in the “End Routine” section of the routine’s code component:

if P1_i == 30:
P1_Loop.finished = True

P1_i is what I’ve called the index for the routine and P1_Loop is what I’ve called the loop. Each rep uses one place in the index.

What specifically went wrong when you tried that?:
The experiment still stayed stuck on the 30th trial. It just repeated the trial over and over again.

The nReps value in the loop specification is the number of times that the spreadsheet is repeated so 30 repeats of a spreadsheet with 50 rows would be 1500 trials. Set nReps to 1 unless you do want the spreadsheet repeated.

Do you have any other loops around P1_loop that might be repeating it?

I assume that your index variable is being incremented correctly.

Oh interesting! I’m not using a spreadsheet, actually. I use a combination of an image component and a code component, where I define the image component as a file path plus a list of images plus the file itself, as such:

P1_Trials = P1_Path + P1_Trials_List[P1_i] + P1_File

Because there are 30 images, I set the loop to 30 repeats assuming that each repeat of the routine would show a new image. I do get to see all 30 images, but it just repeats the 30th over and over. When I lowered the nReps to 1, I only saw one of the images, and it also repeated itself endlessly.

I have it set up this way for several other routines in the experiment and the routines repeat according to the nReps I specified in the loops. They advance to the next routine after the specified number of repeats just fine, but this particular routine just repeats endlessly.

Apologies if this is hard to understand! I’m very new to Psychopy and coding in general.

If you aren’t using a spreadsheet then nReps to 30 is fine but you therefore don’t also need code to stop the loop repeating at 30 reps (or possibly 31 since Python usually starts counting at 0).

Please could you show a screenshot of your flow? You could add a text box to display the value of your index to monitor what’s happening.

Thank you so much for your help and attention so far!

Here’s a screenshot of my flow. I created the textbox as you suggested. With each trial, the value of the index goes up by 1 and it stops displaying values at 29, which makes sense since I have 30 items in the list. The final image is still repeating over and over, however. I can still interact with each repetition as I did with all of the previous, indexed, ones, but the textbox no longer displays any index value.

Upon further inspection it seems that the routine is advancing to P2, but the final image (P1_i = 29) from the P1 routine is staying on the screen. I added a textbox to display the index value to the P2 routine and the index value is indeed increasing as it should. However, the final trial image from the P1 routine is remaining on screen after P1 ends and is being counted as each trial for P2. P2 is set up identically to P1, just with a different list of images and with “P2” in place of “P1” for every relevant variable, so I’m not sure why it isn’t reading from the list I designated in the P2 code component.

1 Like