Participant generated text not clearing between routines

*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:

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…


respDisplay = “”
maxDigits = 6

#key logger defaults
last_len = 0
key_list =

#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

#check for backspace
if("backspace" in key_list):

    #if we have at least 1 character, remove it
    if(len(key_list) > 0):

#if enter is pressed then...
elif("return" in key_list):
    #remove the enter key

    #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):
#create a variable to display
respDisplay = "".join(key_list)


thisExp.addData(‘subjResponse’, respDisplay)

When you change routine, are you changing the name of the keyboard component in your code?

Hi Wakecarter, thanks for your reply,
Yes, the keyResp is changing names between routines! I changed them in the script and it is working :smiley: thanks so much!