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.