Restarting, not discarding, a trial when eyetracking fixation is lost

OS: Win11
PsychoPy version: v2025.2.3beta
Standard Standalone Installation? yes
Do you want it to also run online? no
What are you trying to achieve?:

I have made an experiment where participants must fixate centrally in order for stimulus to be shown. If they look away from the stimulus, the trial ends. My builder screen for my trial routine looks like this (the test routine checks whether fixation is still maintained):

However, I want to restart the trial when fixation is regained, not end the trial entirely. I want to collect exactly 100 trials worth of data from my participants, but this current method would collect fewer than that as it skips trials where fixation is lost without replacing them.

Pausing (if the stimulus is removed from the screen) and unpausing the trial would also work.

I think “trials.rewindTrials()” or “trials.rewindTrials(1)” is what I need for this to work, but I don’t have a code component currently, and I am not sure where would be best to include the code component for it to work.

What did you try to make it work?:

I tried implementing a code component with “trials.rewindTrials()”. I know it will need to be in an if statement somewhere… just unsure what specifically to do here.

Something along the lines of “if roi.lookAway = true, then trials.rewindTrials()”, right?

Link to the most relevant existing thread you have found:

Specifically this post:

Thanks for your help in advance!

So technical issues aside, this is HIGHLY unethical from a data collection/experiment design perspective. Most, if not all, research that requires central fixation will just throw out bad trials (looking away from fixation).

Restarting the trial leads to increased practice effects in the overall task and the individual trial types. It also leads to additional participant fatigue, and appropriate participant compensation (for longer testing times) needs to be addressed.

Participants will always have trials where they fail in this task, and that’s not even accounting for trials/participants have good tracking at the start OR that calibration went well.

Part of central fixation-based research is incorporating the difficulty of keeping fixation on a central fixation cue while moving the attentional spotlight to peripheral stimuli at the same time. It’s similar to asking participants to repeat trials where they got the secondary task in a dual task paradigm wrong, it’s not appropriate.

For the actual fix. Make sure you identify the area that your ROI exists in

ROI_area = [x1,y1], [x2,y2],[x3,y3],[x4,y4] #a square
bad_trial = False
 #then in each frame
if this_eye_xy is not in bounds of ROI_area:
         bad_trial = True
#end of trial
if bad_trial == True:
      trials.rewindTrials() 

TLDR: This is not a proper way to approach eye data based research, and a reviewer will bring it up. But here is a solution.

Issac