psychopy.org | Reference | Downloads | Github

Score mouse responses and RTs

If this template helps then use it. If not then just delete and start from scratch.

OS : Windows 10
PsychoPy version : v2020 1.3
Standard Standalone? Yes
What are you trying to achieve?: I am creating a decision task in which participants must answer via mouse clicks if a vertical bar on the screen fits a space. Participants have 1500ms to make a response before the next stimulus appears (mouse clicks should not force the end of the routine). I need to measure their RTs and score their responses to display a score on the screen .

What did you try to make it work?:
I added the following code component at the end of the routine. In the mouse properties, I set it to save the mouse state on clic. It works perfectly when I set no time limits for the mouse responses and force the end of the routine on any clic. However, when I set the duration of the mouse component to 1500ms and disable the end of the routine on press, mouse.getPressed() returns an empty list [0,0,0] in the data file, albeit the mouse presses are detected, as showed by the columns “respFit.leftButton”, “respFit.rightButton”, and “respFit.time” (see below).

I also do not understand why the data in the output file comes as a list between brackets, whereas it was stored without the brackets in the previous version (without the time limit).

Here is my code:

# begin routine tab
score = "Points : " + str(p) # to be displayed on the screen

# end routine tab

# Scores mouse response. I named the mouse as "respFit".
if respFit.getPressed() == [1,0,0] and resp == 'left': #left mouse button
    acc = 1  #correct response
    # Stores current reaction time
    fitRT = respFit.time[0]
    # Adds the RT and the response of the current trial to a list.
    # Used merely to double check in the output file. 
    fitRT_list.append(respFit.time[0])
    fitAcc_list.append(acc)
    print('RT in trial '+ str(fit_counter)+' = ' + str(respFit.time))
    thisExp.addData('fitRT', fitRT)

elif respFit.getPressed() == [1,0,0] and resp != 'left':
    acc = 0  #incorrect response
    # Stores current reaction time
    fitRT = respFit.time[0]
    # Adds the RT and the response of the current trial to a list.
    # Used merely to double check in the output file. 
    fitRT_list.append(respFit.time[0])
    fitAcc_list.append(acc)
    print('RT in trial '+ str(fit_counter)+' = ' + str(respFit.time))
    thisExp.addData('fitRT', fitRT)
 

elif respFit.getPressed() == [0,0,1] and resp == 'right': #right mouse button 
    acc = 1  #correct response
    # Stores current reaction time
    fitRT = respFit.time[0]
    # Adds the RT and the response of the current trial to a list.
    # Used merely to double check in the output file. 
    fitRT_list.append(respFit.time[0])
    fitAcc_list.append(acc)
    print('RT in trial '+ str(fit_counter)+' = ' + str(respFit.time))
    thisExp.addData('fitRT', fitRT)

elif respFit.getPressed() == [0,0,1] and resp != 'right':
    acc = 0  #incorrect response
    # Stores current reaction time
    fitRT = respFit.time[0]
    # Adds the RT and the response of the current trial to a list.
    # Used merely to double check in the output file. 
    fitRT_list.append(respFit.time[0])
    fitAcc_list.append(acc)
    print('RT in trial '+ str(fit_counter)+' = ' + str(respFit.time))
    thisExp.addData('fitRT', fitRT)

elif respFit.getPressed() == [0,0,0]:
    acc = 0

p = p+acc # updates score
thisExp.addData('fitAcc', acc)
thisExp.addData('fitScore', p)               # adds the total score to the output file
thisExp.addData('fitNumTrial', fit_counter)  # adds the number of trials


# updates the score displayed on the screen

score = "Points : " + str(p)

What specifically went wrong when you tried that?:
This is a screenshot of the data file when there is no time limit for the mouse response and it forces the end of the routine :

And here is a screenshot of when I set a 1500 ms limit and disable the mouse to end the routine:

I really appreciate your help.

Hi There,

Please could I check why it is that you are using a code component to return mouse response times? this should be possible using the mouse component alone with the “end routine on press” set to never “save mouse state” as “on click”

Thanks!
Becca

Hi Becca,

Thanks for your reply.

I will explain: I need to use the mean RT in the training phase of the task as parameter in the following blocks of my task. Each participant will perform a block of trials that are self-paced in a pre-determined pace and a block of trials with an adapted pace corresponding to 1,5*RT (their mean RT in the training phase). I inserted this code component to update the score displayed on the screen during the practice trials and to make the program automatically calculate the mean RT at the the end of the practice block.

Do you have another suggestion on how to achieve this? I’ll be very thankfull if so :slight_smile:
Luísa

Sure yes! So you actually don’t need a huge code component for that (I am sure you’ll be pleased to hear!) - here is a demo where you would make 5 mouse responses in the training and then the average is calculated and showed at the end (for your experiment you would just use the value of avRT for setting the parameter you need to).
trackMouseTimes.psyexp (12.6 KB)

Hope this helps,
Becca

1 Like