*OS Win10
*PsychoPy version 2022.2.2
Hi all,
I’m trying to create a series of short routines at the start of my experiment to gather demographic data from participants, like age, sex, gender etc. which I would like participants to be able to type answers and see them on screen.
The first routine displays an image with my question on it reading “Welcome, please enter your age using the number keys, then press enter”.
I’m using the script from Dr Ozubko’s YouTube tutorials to allow participants to see their typed responses: https://www.youtube.com/watch?v=potgz60IGcs&list=PL6PJquR5BWXllUt585cRJWcRTly55iXTm&index=12
I will paste the script in a moment, but first here is the issue I’m having:
The first routine works perfectly in that the participants can type their age using numbers keys and see the numbers on the screen. However, when they press ENTER to break to the next routine, one typed number remains on screen on the next routine, and participants are no longer able to type a response to the next question, or interact in any way using the keyboard. The only way to proceed is the ESC out and try to troubleshoot, but so far I am having no luck trying to figure out what is wrong.
Hopefully someone can help :-S
Here is Dr Ozubko’s script, and I have added the ‘break’ line to end the routine and go to the next question, which I have asterisked below…
BEGIN ROUTINE:
respDisplay = “”
maxDigits = 6
#key logger defaults
last_len = 0
key_list =
EVERY FRAME:
#if a new key has been pressed since last time
if(len(keyResp.keys) > last_len):
#increment the key logger length
last_len = len(keyResp.keys)
#grab the last key added to the keys list
key_list.append(keyResp.keys.pop())
#check for backspace
if("backspace" in key_list):
key_list.remove("backspace")
#if we have at least 1 character, remove it
if(len(key_list) > 0):
key_list.pop()
#if enter is pressed then...
elif("return" in key_list):
#remove the enter key
key_list.pop()
**break**
#and end the trial if we have at least maxDigits digits
if(len(key_list) >= maxDigits):
continueRoutine = False
#now loop through and remove any extra characters that may exist
while(len(key_list) > maxDigits):
key_list.pop()
#create a variable to display
respDisplay = "".join(key_list)
END ROUTINE:
thisExp.addData(‘subjResponse’, respDisplay)