psychopy.org | Reference | Downloads | Github

Inserting pauses in PsychoPy image experiment after every 20 trials

OS (e.g. Win10): Using MacBook Air (Model A1466)
PsychoPy version (e.g. 1.84.x): v3.1
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?: Inserting breaks within loop that shows images after every 20 trials

What did you try to make it work?: We inserted this code within our image loop using the coder component in the builder window

if trials.thisTrialN > 0 and trials.thisTrialN % 20 == 0: 
    finish.trials = True;

What specifically went wrong when you tried that?: It gave us breaks when we need it to for the first time, but then it exited out of the loop. We need 1000 trials with breaks every 20 trials, this code gave the first break but then stopped showing the next set of 20 images.
We tried setting the nReps option to a higher number to make it show more images after the break, but in that case it started repeating images which is not an option for our experiment.

Include pasted full error message if possible. “That didn’t work” is not enough information.
There is no error message because the code executes fine, it just ends before we need it to end. This is a screenshot of our experiment in the builder, the screen is on the image trials loop.

That should be trials.finished = True (and semi-colons are not needed in Python).

The code (if correctly typed) would be doing exactly what you tell it to (exit the loop the first time the condition is met).

You don’t want that. Instead, in your “pause” routine, insert this in the “begin routine” tab of a code component:

if trials.thisN > 0 and trials.thisN % 20 == 0:
    continueRoutine = True
else:
    continueRoutine = False

i.e. you don’t want to exit the loop, you just want to control whether the “pause” routine runs on a trial or not.

Thank you for responding!
So when I tried putting that code into the begin routine tab of the pause routine and removed the previous code, it stopped giving the breaks altogether. It didn’t give out any error message.
(The code in the screenshot says % 2 because in our test file for the code we only have 10 images, also the 4 was an accidental type after False while screenshotting, I did remove it and try again but got the same result).
Another problem is that the code repeats the images it shows while randomizing them, and in our experiment we need the images shown to not repeat. Is there any way to ensure this on PsychoPy?

OK, I was just copying and pasting your code, so I guess .thisTrialN should actually be .thisN. The various trial counters are explained here:

https://www.psychopy.org/api/data.html#trialhandler

“The code” isn’t doing this, you are :wink:. Computers only do what they are told to do…

We can’t really explain this without seeing the details of your conditions file contents and how you have specified the settings in your loop dialog. But given that .thisTrialN didn’t work for you, I’m going to guess that you have specified a value for nReps that is greater than 1, and that hence, by definition, the contents of your conditions file will be repeated.

If you don’t want any repetition, then set nReps to 1 and ensure that your conditions file contains enough rows to provide for unique stimuli on each trial (i.e. that there is one row per trial).