psychopy.org | Reference | Downloads | Github

Text Input in loop - last input flashes bevor the new one

Hi all :slight_smile:

URL of experiment: Sign in 路 GitLab

Description of the problem:

I am new to psychopy and to coding as well and put something together from here and there. 5 words are displayed to the participant. Afterwards, they have to write down as many words as they remember. Therefore I created a loop so that they can write the word and after hitting enter, they can write the next word. This happens five times or if the time limit of 30 seconds is reached, it will exit the loop automatically. It works fine in psychopy but in pavlovia, after hitting enter, the word which was just written down flashes for a few milliseconds.

The java code is:
Begin Routine:
respDisplay = 鈥溾;

//key logger defaults
last_len = 0
key_list =

if ((trials.thisN === 0)) {
startTime = globalClock.getTime();
}

Each Frame:
//if a new key has been pressed since last time
if(keyResp.keys != undefined && keyResp.keys.length > last_len) {

//increment the key logger length
last_len = keyResp.keys.length

//grab the last key added to the keys list
key_list.push(keyResp.keys.pop())

//check for backspace
if(key_list.indexOf("backspace") != -1) {
    key_list.splice(key_list.indexOf("backspace"), 1)
    
    //if we have at least 1 character, remove it
    if (key_list.length > 0) {
        key_list.pop();
    }
}
else
//if enter is pressed then...
if(key_list.indexOf("return") != -1) {
    //remove the enter key
    key_list.pop();
    
    //and end the trial if we have at least 2 digits
    if (key_list.length >= 2) {
        continueRoutine = false;
    }
}


//create a variable to display
respDisplay = key_list.join("");

}

if (((globalClock.getTime() - startTime) >= 30)) {
trials.finished = true;
continueRoutine = false;
}

End Routine:
psychoJS.experiment.addData(鈥渟ubjResponse鈥, respDisplay);

Grateful for every help!
Best, Nicolas

Is the text object set to display respDisplay every Frame?

Try text.text = '' in Begin Routine to set it as blank before the first frame (if the text object is called text).

Personally I tend to set this kind of text object as a single space / constant in the component and then update the text in an Each Frame code component, but only when it changes.

e.g.

if respDisplay != oldDisplay:
     text.text = respDisplay
     oldDisplay = respDisplay

Yes the text input is set to display respDisplay every Frame.

This is my setup:

What I tried now was to change the code in Begin Routine in 鈥渃odeResp鈥 to:

text.textInput = 鈥溾;

respDisplay = 鈥溾;

//key logger defaults
last_len = 0
key_list =

if ((trials.thisN === 0)) {
startTime = globalClock.getTime();
}

That didn鈥檛 work. But did I do it the way you meant it?

And thank you for your help of course!

Move codeResp to the top of the routine.

Did you add textInput.text = 鈥 鈥 in Begin Routine?

I moved codeResp to the top now.

Old Begin Routine:
respDisplay = 鈥溾;

//key logger defaults
last_len = 0
key_list =

if ((trials.thisN === 0)) {
startTime = globalClock.getTime();
}

New Begin Routine:
text.textInput = 鈥溾;

respDisplay = 鈥溾;

//key logger defaults
last_len = 0
key_list =

if ((trials.thisN === 0)) {
startTime = globalClock.getTime();
}

Still the same problem. When doing the online experiment, after writing down the first word and hitting enter, to word disappears and flashes up again for a few milliseconds and then disappears again. This happens every time hitting enter except the last (5th) time.

It should be

textInput.text = " ";

Ahh shoot my bad. But it works now perfectly online as well!

Thank you a lot for your help! Really appreciate it!