[ONLINE/JS] Display message when a response is made within the same routine

Within the same routine, participants hear an audio and have to make a response at any point within that audio, but during the whole experiment the background screen is black so in order to reassure to the participant that their response was recorded I want to briefly display a message (e.g., “response recorded!”) when they press any of two keys. Crucially, when they make a response the routine does NOT end, it continues until the audio is over.

I want to do this online, preferably with a simple code that doesn’t need to go to the output data file, cause I don’t need to check if response was correct or not, just if the participant pressed any of the two keys I instructed.

if len(keys) and responseRecorded==0:
     if 'a' in keys or 'b' in keys:
          text_1.text='Response recorded!'

event needs to be defined in code_JS as per my crib sheet. text_1 is the name of the text component which should be set to blank and constant.

1 Like

Thanks for responding @wakecarter

I created text_1 set to blank and constant, and added the code component in begin routine (I defined “event” in JS as per your crib sheet) is there anything I am missing? cause it is not working, but it is not giving me error either (although when I ran it offline, it gave me “responseRecorded” undefined).

You need respondRecorded=0 in Begin Routine

Now it is starting to work in PY, but the message appears at the beginning of the next routine instead of the exact moment of the key press. In JS, it gives me code error (_pj is not defined, but that was part of the automatic translation the software gave me), I only defined “event”, anything else I can try?