Display "response recorded" message after specific key presses


I am creating an experiment (online) where there is a decision (they have to respond yes or not for a word that appears on the screen), and I want to display the message “Response recorded!” when they press either key (l or a). I tried using the feedback coding and added a feedback_text component and a code component:

#Begin experiment

#End of routine
if resp.corr:msg="Response recorded!"

but it only works for correct responses and, most importantly the message only appears AFTER the key_resp component duration is over (they have 3 seconds to respond), because I DO NOT want to force end of routine after the response.

During each trial an audio plays, so I do not want the routine to stop immediately after the response, but only when the audio ends. But I want the participant to know that her/his response was recorded so I want to display a message in the screen as soon as they respond (correct or incorrect, just response recorded).

What you want is a text component with static text content, and just control its visibility so that it appears when a response is made.

This code is Python- you’ll need to translate for online.

At the beginning of the routine:

text_visibility = 0

Each frame:

if len(resp.keys) > 0:
    text_visibility = 1

And put $text_visibility in the opacity field of the text stimulus, set to update on every frame.

Thank you for your response @Michael
It is not working-- maybe I am missing something, the message is displayed during the whole routine (before any key is pressed), opacity does not change. I am still working and testing in the desktop. I tried moving the components in the routine and change durations, but text still displays during the whole routine.

Screen Shot 2020-06-29 at 8.35.27 PM Screen Shot 2020-06-29 at 8.35.21 PM

Oh, I keep forgetting and rediscovering this bug (specific to text stimuli). See below for a discussion and a workaround (ie use another sort of stimulus to hide and then uncover the text stimulus):

This is an interesting solution. It worked with the polygon, thanks so much.

Hi @Michael, you helped me with displaying a messages (playing with the opacity in a polygon), it worked perfectly in builder, but now that I just uploaded it on Pavlovia I am getting an error right before that routine (although I use AUTO>JS).

Here is attached what I did and the error message: * TypeError: Cannot read property ‘length’ of undefined it seems light the variable was undefined, but I doubled checked that the code is calling the right variable. Please, could you guide me on what is happening?

Screen Shot 2020-07-16 at 7.08.06 AM

Sorry, I’m not familiar enough with JavaScript to be of much help here.

Yet the error tells us that the variable is undefined… So perhaps you need to check for that before trying to access its length, e.g. if ( typeof x != 'undefined' ) {# do stuff}

1 Like

Thanks for your promptly response @Michael
I probably won’t be able to solve this, but in the meantime is there a simpler way to display my message. For example every time participant press the key ‘a’ or ‘l’ the message “response recorded!” is shown for a few seconds. That way there is no need for JS to check the resp.keys variable. Or is this a more complicated solution than before?

Is there something like the following (I am very not skilled in programming):

if 'l':
 print "message recorded!"

Hi @Laura_Pissani,

I’m struggling to replicate this problem, what version are you using? It may already be fixed in the latest release but I want to be sure before marking it as fixed.

Hi @TParsons, thanks for responding, I have Psychopy3 v2020.1.2 (but in settings 2020.1) could that’be the problem? I’ll switch and check now.

Do you mean, you are manipulating the opacity of the polygon using the above code and uploaded online and it worked? cause sadly I still have the same message (undefined) error.

Sorry, I am really trying to update to v2020.1.3 (Issue with psychopy 2020.1.3 installation (it goes back to v2020.1.2)) but I can’t and the current version keeps freezing everytime I synchronize or upload it as a new experiment. As soon as I am able to have Psychopy working I will test this, don’t mark it as solved it just yet, please.

Hi Laura,

I’m trying to replicate the text opacity bug, but when I set the opacity of text on my own install it seems to work. If you’re using one of the newest versions then it probably isn’t a version error, unless it’s been fixed very recently, so I’ll look further into what’s going on. Could you send me the full .psyexp / .py files for your experiment so I can test it out?



Hi @TParsons, I went back to using the text component but the opacity actualization did not work, as it does with opacity in the polygon. I am attaching the .psyexp file with the text not working. Also, if you have an idea on how to get this to work online, that’d be much appreciated.

CMLP_desktop.psyexp (57.7 KB)