Gaze-contingency Loop only Works on First Iteration

Hello everyone!

I am seeking help to make my gaze-contingent trials work.

I am currently programming an experiment where the trials do not progress without proper gaze fixation on the center of the screen (using an Eyelink 1000 plus eye tracker). I have built a few nested loops to ensure proper fixation before flashing the display for a given trial. This works for the first iteration/trial, but as you can guess from my posting here, there are problems. Every trial after the first just continues without measuring gaze. Does anyone know why this would be?

I will attach the part of my code that feels involved with the problem, and I will attach a shortened version of my entire script to this post.

Thank you all for your help! I really appreciate it.

example_psychopy.py (13.9 KB)

if eye_track: # if we're using the eyetracker, use the gaze-contingency check before showing the trial

            raw_sample = eye_tracker.getNewestSample()
            if raw_sample == None: # if eye tracker cannot find an eye
                gaze_pos = [-32768, -32768] # setting a random position 
            else: 
                if eye_used == 0 or eye_used == 2: 
                    gaze_pos = raw_sample.getLeftEye().getGaze()
                elif eye_used == 1:
                    gaze_pos = raw_sample.getRightEye().getGaze()

            x_py = gaze_pos[0] - 960 # x coordinate of eye-tracker translated into pixel on monitor 
            y_py = 540 - gaze_pos[1] # y coordinate of eye-tracker translated into pixel on monitor 

            # waiting for fixation to display Gabors 
            min_fixation_gaze_time = .5 # minimum fixation time of .5 seconds 

            display = False # setting display as false so the trial doesn't continue until conditions are met 
            while not display: # while we are waiting to show the trial
                
                outside = False
                
                if (x_py < minimum_x) or (x_py > maximum_x) or (y_py < minimum_y) or (y_py > maximum_y):
                    outside = True
                    break
                    
                elif (minimum_x < x_py < maximum_x) and (minimum_y < y_py < maximum_y): # if the participant's gaze is within the boundaries

                    fixation_gaze_time = core.Clock() # initialize the clock
                    
                    while fixation_gaze_time.getTime() <= min_fixation_gaze_time:
                        
                        if (x_py < minimum_x) or (x_py > maximum_x) or (y_py < minimum_y) or (y_py > maximum_y):
                            outside = True
                            break
                    
                    if not outside and fixation_gaze_time.getTime() >= min_fixation_gaze_time: 
                        display = True
                    
            eye_tracker.sendMessage(f'trial {trial} display start') # send a message to the eye tracker when the display has started

            # display the Gabors!            
            while display: # while display is active 
                
                if (x_py < minimum_x) or (x_py > maximum_x) or (y_py < minimum_y) or (y_py > maximum_y): # if gaze x/y is less than min or max x/y while the display is active and time is a' tickin
                    list_of_objects.append(condition) # make the participant view this set of conditions again later 
                    trials += 1 # and add a trial to the total number of trials

                # displaying the gabors for one frame (refresh rate of eyeTrackMon is 60Hz, then each frame is ~16 msec)
                win.flip() # display!
                win.flip() # clear screen

                display = False
            
            eye_tracker.sendMessage(f'trial {trial} display end') # send a message to the eye tracker when the trial has ended
    
        else: # just do the display if no eyetracking

            for p in pos: 
                gabor.pos = p
            gabor.draw()
            win.flip() # display Gabors
            win.flip() # Gabors offset