psychopy.org | Reference | Downloads | Github

Mysterious text component displays variable from previous trial

Hi,

I have a routine where the participant types freely to indicate the duration between two visual stimuli (i.e. before the “ms” in the screenshot below).

I use the code below in each frame to gather the user input in real-time:

L = event.getKeys();
    
if (L.length>0) {
    if ((allowedKeys.some(r=> L.includes(r))==true)) {
        userInput = userInput + L;
    } else if ((L.includes('backspace')==true)&&(userInput.length>0)) {
        userInput = userInput.substring(0,userInput.length-1);
    }
}

Issue: For each trial, the user input from the previous trial will flash for ~1 frame (in front of the “ms”) and then disappear. For trial 1, it’ll flash “undefined”. I reset userInput to empty after each trial, but it doesn’t seem to help.

The problematic text component is as below:

I was wondering why I see that flash at the beginning of each trial.
You may try out the task and see the issue using the link: masking_p2 [PsychoPy]

I’d really your help with troubleshooting this issue.
Thanks.

Your code component should be above your text component.

Yes, the code component is the very first component in that routine.

@wakecarter Any other reasons you can think of?
I should also mention this: I have the local version (PsychoPy) of the task as well. Same code, but no issue.

If resetting it in Begin Routine doesn’t work then try End Routine so it gets reset immediately after use.

Alternatively, set it to a space constant and then set in code with text_x.text =