Continue presenting a visual stimulus for varying duration after response

waitKeys, like core.wait, just stops everything else from executing.

So let me check if I understand this correctly: The stimulus starts and is present for 500ms. Anytime in that 500ms or for 1 second after the end of the stimulus, the participant can respond with a key-press. 600ms after that happens, the next trial should begin. If they do not respond, presumably you just want the next trial to start 600ms later than that.

Very simple modification:

for i in range(0, numTrials):
    # at the start of the stimulus onset
    startStim = core.getTime() # Gets a timestamp of the start of the display
    respRecorded = core.getTime()+1.5 # A placeholder for the time of response, 
    # defaults to end of the 1500ms response window. 
    responded = False # So you only get one response
    trialDone = False # Adding this to do some parallel tracking
    while core.getTime() - startStim < 1.5 and not trialDone: # Now this runs 1500ms OR until trialDone is set to true.
        if core.getTime() - startStim < .5: #For the first 500ms of that time, draw the thing.
            stim.draw() # Draw your stimuli and flip the window so it displays. 
        elif responded: 
            # If the stimuli are done AND the participant has already responded, break this loop.
            trialDone = True 
        win.flip() 
        resp = event.getKeys()
        if len(event.getKeys()) > 0 and not responded: # Checks both for a response and if they have already responded or not
             # Do whatever you need to do for your responses here.
             responded = True
             respRecorded = core.getTime() # Creates a new timestamp at the time of response
    while core.getTime() - respRecorded < .6: # This will start checking whenever the above loop ends.
        pass # Simply waits until 600ms have passed from respRecorded before 
        # going to the next iteration of the loop

If you don’t want the 600ms waiting period if they don’t respond in the 1500ms window, i.e. you want the next trial to start on immediately after the 1500ms window has ended if no response has been recorded, just set respRecorded’s initial value back to core.getTime() + .5. That way, if they don’t respond in 1500ms, when the next loop that checks for the 600ms window starts, it will immediately be false and just go on to the next iteration.

1 Like