Hi, I am trying to set up a basic digit-span task where participants are show a picture of a digit, one at a time. They then are prompted to type all digits that they saw. Right now, I am using the code component below in builder to give the participants the ability to see what they are typing on the screen. This code displays anything the participants type, and the routine is ended when enter is pressed.
My issue has been getting Psychopy to output the corrAns based on the final string of text entered (see attached conditions file). The final inputText string has to be compared, rather than recorded key presses (e.g., [‘4’, ‘5’, ‘RETURN’] ), because participants have the ability to use backspace in case they mistype something. With backspace enabled, endless amounts of correct correct responses, such as [‘4’, ‘6’, ‘BACKSPACE’, ‘5’, ‘RETURN’], are possible. Thus, the only way to compare to corrAns would be to compare corrAns with the final string of text (inputText) submitted. However, keyboard_resp_13.corr outputs a 0 regardless of whether the string of numbers submitted matches the corrAns.
Code Component:
Begin Experiment
inputText = “”
Begin Routine
theseKeys=""
shift_flag = False
Each Frame
n= len(theseKeys)
i = 0
while i < n:
if theseKeys[i] == 'return':
# pressing RETURN means time to stop
continueRoutine = False
break
elif theseKeys[i] == 'backspace':
inputText = inputText[:-1] # lose the final character
i = i + 1
elif theseKeys[i] == 'space':
inputText += ' '
i = i + 1
elif theseKeys[i] in ['lshift', 'rshift']:
shift_flag = True
i = i + 1
else:
if len(theseKeys[i]) == 1:
# we only have 1 char so should be a normal key,
# otherwise it might be 'ctrl' or similar so ignore it
if shift_flag:
inputText += chr( ord(theseKeys[i]) - ord(' '))
shift_flag = False
else:
inputText += theseKeys[i]
i = i + 1
End Routine
let’s store the final text string into the results finle…
thisExp.addData(‘inputText’, inputText)
inputText=""
Conditions excell file:
3digits_1.xlsx (9.1 KB)
Key_res properties:
Example output data:
_Trial_2017_Nov_16_1434.csv (788 Bytes)