Reaction time set to zero on every stimulus

Hi, everyone! I have an experiment where people have to say if two figures are the same or not. The first figure appears at 1sec, the second at 2sec and the “right/wrong” buttons at 3sec, and I have the following code to keep track of the time on the routine of the feedback, which plays sounds for when it’s right or wrong. Unfortunately, the time between routines is not constant and it keeps adding time so I can’t calculate the real reaction time. Does anyone know how to set it to zero once the “right/wrong” buttons are on the screen?
Begin Experiment


soundfile = ['files/sound_correct.wav', 'files/sound_wrong.wav']
clock = core.Clock()
resultats = open('training_resultats.txt', 'w')

Begin Routine

if correct.contains(mouse):
    sound = soundfile[1]
    resultats.write('1 correct ' + str(clock.getTime()) + '\n')
else:
    sound = soundfile[0]
    resultats.write('1 wrong ' + str(clock.getTime()) + '\n')

You need to do this:

clock.reset()

at the appropriate time (e.g. at the start of the routine where you collect the response), otherwise the clock just keeps counting up indefinitely from when it was first created.

I think you could even synchronise that exactly with the first frame drawing on the routine, like this:

https://www.psychopy.org/api/visual/window.html#psychopy.visual.Window.callOnFlip

Also it doesn’t seem right to put code to collect the reaction time in the “Begin routine” tab: either the response hasn’t had a chance to be made at that stage, or if it is in a subsequent routine, the stimuli you are checking to see if they contain the mouse aren’t being displayed anymore.

thanks, you really solved my problem! I didn’t learn how to use the callOnFlip but taking out the time it takes for the buttons to appear actually gives the real reaction time!