OS: Win 10
PsychoPy version : 3-3.1.5 (Builder)
Hello, I wanted to design an experiment like this:
In a competing task, two participants were asked to press the “Z” and “M” keys as quickly as possible when a stimulus signal was presented.
If the reaction time difference is within 50ms, the two people are tied.
If the reaction time difference is greater than 50ms, the faster player wins.
My question is:
How do I compare the reaction times of the two keys in each Trail?
As far as I know, .rt is a list. How to compare the size of two lists?
@Wenrui , you can use the following in the “End Routine” tab, where your keyboard component is called “key_resp”, and the keyboard is set to record “all keys”:
def getRT(kb, player):
# Get first response or return false for no resp
idx = 0
for key in kb.keys:
if key == player:
idx += 1
def getDiff(p1, p2):
if abs(p1 - p2) < .050:
# p1 win
elif (p2 - p1) > .050:
# p2 win
elif (p1 - p2) > .050:
# Get first response from each player
p1RT = getRT(key_resp, 'z')
p2RT = getRT(key_resp, 'm')
# If both responded
if p1RT and p2RT:
result = getDiff(p1RT, p2RT)
# no responses from p1 or p2
elif not p1RT and not p2RT:
# p2 no response - p1 wins
# p1 no response - p2 wins
You can put those functions in the Begin Experiment tab.
Thank you very much for your help! Your code inspired me a lot!
Before receiving your help, I took the following code, and basically solved my problem.
#According to different game results, participants were presented with different responses and result pictures.
respone1 = 0
result1 = 0
#When both players have pressed the key, the game response and result are presented.
if len(select_1.keys) ==1 and len(select_2.keys) ==1:
continueRoutine = False
#Comparing the reaction time of players in the game, three different responses and results are presented.
if select_1.rt < (select_2.rt - 0.05):
elif select_1.rt > (select_2.rt + 0.05):
elif select_1.rt > (select_2.rt - 0.05) and select_1.rt < (select_2.rt + 0.05):