Reply To: Trying to set a unique participant ID/code for Amazon Mechanical Turk payment

PennController for IBEX Forums Support Trying to set a unique participant ID/code for Amazon Mechanical Turk payment Reply To: Trying to set a unique participant ID/code for Amazon Mechanical Turk payment

#6411
Jeremy
Keymaster

Hi,

Blocks of trial commands are actually arguments passed to the newTrial function (PennController has been deprecated for a few versions now) and, as such, they are evaluated at the very beginning of the experiment. Which means that the string you pass to your newText command is also evaluated before any trial has effectively run, ie. before your "ParticipantID" Var element has been instantiated.

I don’t think you really need to use a PennController Var element in this case; you should probably just use a good old javascript variable at the top of your script:

const participant_id = b64_md5((Date.now() + Math.random()).toString());

Then you can do things like newText("code", "<p>Your unique identifying code is: "+participant_id+"</p>")) and .log("Participant id", participant_id) on the closing parenthesis of newTrial (PennController)

Let me know if you have questions

Jeremy