How to display the Participant ID

I’m going to recruit participants from mturk/prolific, then use qualtrics to generate a participant ID, pass this to psychopy/pavlovia then at the end of the experiment, display their participant ID for them to enter as a completion code. I can pass the code from qualtrics to psychopy/pavlovia by I can’t seem to display the participant ID.

What did you try to make it work?:
I’ve added a routine with a text block:

and the following in a code component:

msg = "You have now finished. MTURK CODE:" + expInfo['participant'];

What specifically went wrong when you tried that?:
In PsychoPy I get the message "NameError: name ‘msg’ is not defined, and in Pavlovia, I get a screen that displays “Hello World”, not the message I’m trying to display.


The variable msg needs to be defined before the text component tries to use it.

So your code should be put in either the “Begin experiment” tab of your code component, or if it is in the “Begin routine” tab, the code component needs to be above the text component (you can re-order components by right-clicking on their icons).

1 Like

Thanks Michael. That worked in PsychoPy, but it’s still displaying “Hello World” in Pavlovia.

The JS code is:

msg = ("You have now finished. MTURK CODE:" + expInfo["participant"]);


I had a very similar problem just now and figured it out. I think Micheal is right. You do not define “msg” this variable properly, so Pavlovia is not able to read it and present “Hello World”. Perhaps it seems that you defined, but somehow the order of your codes or putting it into wrong tabs makes Pavlovia think you don’t define “msg”.

The thread below also inspires me. Hope it helps.

Thanks Wanyin - that was helpful. In the end it turns out I had defined the variable msg twice in different ways.

1 Like