How to repeat a trial with no response at the end of a loop?

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2022 1.2
Standard Standalone? (y/n) Yes
What are you trying to achieve?:
In my task, participants have to keypress in each trial. But there could also be trials when they fail to respond. I would like to take the same missed trial and present it at the end of the loop.
What did you try to make it work?:

I have 2 loops. In the outer loop, I have added a code component with the following code:

row_list = list(range(3)); % trial number for each trial in a block
row_list.reverse(); # need the lowest values last, which get popped first
current_trial_num = row_list.pop(); # get the initial value

I add the current_trial_num variable to the “Selected rows” field in the inner loop. The idea is that if the participant does not miss any trials, the current_trial_num will keep updating itself, till all trials are finished. If a trial is missed, this is added to the end of row_list and is repeated at the end of the loop.
Then, in the inner loop, in a particular routine that determines the participant’s feedback based on key presses, I have this piece of code.

if not choice.keys :
    msg="Failed to respond." # feedback message
    fb_color = 'black'; # color of feedback text
    row_list.insert(-1, current_trial_num) # add the current trial number of the missed trial, to be popped later
elif choice.corr: #stored on last run routine
    msg="You win 1 point!" 
    fb_color = 'green';
    msg="You win 0 points!"
    fb_color = 'red';

And when this routine ends, I add this piece of code.

if len(row_list) == 0: # if there are no more trials to get through, then exit the outer loop
    blocks.finished = True # all trials complete
elif len(row_list) > 0: # if there are still trials to left, pop the row_list
    # update the trial number for the next iteration:
    current_trial_num = row_list.pop();

What specifically went wrong when you tried that?:
All the trials in the initialised row_list work well but a missed trial is still not repeated despite the length of row_list being greater than 0.

It would be great to know if there is a better way to do the same? Or is there a mistake in the code?

Thank you.


I think that the problem is caused by a misunderstanding of Selected Rows which is read when the loop starts. Updating it during a loop won’t have any effect.

I’ve done something similar in one of my consultancy projects but I think I used consecutive loops rather than nested.

Is insert (-1,x) the same as .append(x)?

Thanks @wakecarter. I found a solution to this by basically using consecutive loops.

Hi. I am also trying to repeat a trial with no response. However, I am new to PsychoPy. Could you please share your code? Thank you!

Have a loop at my new Repeat Subset demo

It is an excellent demo! Thank you so much for your help!

1 Like