Hi, I have created an experiment in the builder with a code component. In short, a sound is played, and participants then need to select an image and click on it with the mouse. To get RT, Mouse.time does not work because it registers many clicks, and if I select “End routine on Press”, it registers any click, not restricting it to the image. I think my best option here is to add a code component to get reaction time. I don’t actually know how to do this. The current code I am trying gets me odd numbers in RT (always 0.000… something).
Below is my code component for registering which image has been clicked on + my failed attempt for getting RT.
win.setColor('white')
clock = core.Clock()
for stimulus1 in [ uh, oh, ah, au, u, o, a]:
if mouse.isPressedIn(stimulus1):
timeUsed=clock.getTime() #get the the time used by the subject to respond since a stimulus is displayed.
continueRoutine = False
thisExp.addData('clicked', stimulus1.name)
thisExp.addData('RT', timeUsed)
stimulus1.opacity = 0.2
win.flip()
stimulus1.opacity = 1
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
event.clearEvents()
clock.reset()
The code needs to be revised in line with this post re the visual stimuli:
But re the timing, it is much simpler than you are trying here. Builder maintains a time variable called t which starts at 0 at the beginning of each routine. So just do this:
thisExp.addData('RT', t)
The reason your timing can’t work is you are creating a clock object almost immediately before you ask it for its time, so it will always give you an answer very close to zero. You need to create a clock just once, in advance, and then reset it at the moment you want to start timing from (again, just the once). But Builder is already doing this for you, so just use that.
Thank you for this Michael! It gives me the correct RT values. I have integrated it in the updated code you suggested in the post on ‘Signaling when an image is clicked’.
# check if the stimulus opacity was changed on the last refresh. If so, set it
# back to 1.0 and then end the routine after it is shown again:
if opacity_low:
stimulus1.opacity = 1 # make it fully visible again
opacity_low = False # reset for next trial
continueRoutine = False # end trial after showing stimulus on next frame.
else: # check for mouse clicks:
for stimulus1 in [ uh, oh, ah, au, u, o, a]:
stimulus1.opacity = 1
if mouse.isPressedIn(stimulus1):
thisExp.addData('RT', t)
thisExp.addData('clicked', stimulus1.name)
stimulus1.opacity = 0.2
opacity_low = True
Just note that Builder allows for checking for responses only once per screen refresh. So your timing resolution is limited by the refresh rate of your screen. e.g. you will get more precise (but not necessarily more accurate) RT measurements by upgrading from a standard 60 Hz LCD screen to the increasingly-common 144 Hz gaming-oriented displays.