November 30, 2020 at 11:42 am #6401
I’m trying to set a unique participant ID that I can also use a unique identifying code for ensuring that I’m paying different individuals when recruiting them via Amazon Mecahnical Turk. I’m trying to set this like so:
PennController("consent", newVar("ParticipantID", b64_md5(Date.now() + Math.random())) .global() ...
I thought this would generate a random string, but it seems to always generate 1B2M2Y8AsgTpgAmY7PhCfg. Any idea why this isn’t working?November 30, 2020 at 12:26 pm #6405
It seems I misunderstood the b64_md5 algorithm. What I really wanted was this:
PennController("consent", newVar("ParticipantID", b64_md5((Date.now() + Math.random()).toString())) .global() ...November 30, 2020 at 12:40 pm #6407JeremyKeymaster
Glad you found a solution!
JeremyNovember 30, 2020 at 1:23 pm #6410
Thanks Jeremy! I really appreciate how quick you always are to respond. 🙂
I have a (hopefully) quick followup question. I’m trying to access the value of “ParticipantID” inside of a
newTextelement. I know this is possible by calling something like
newTextelement, but I’d rather not do this because it inserts a bunch of CSS around the element. I want something like this, but this currently returns
undefinedrather than the actual value of “ParticipantID”:
PennController("exit", defaultText .print() , newText("code", "<p>Your unique identifying code is: ".concat(getVar("ParticipantID").value, "</p>")) );November 30, 2020 at 1:32 pm #6411JeremyKeymaster
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.
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
JeremyNovember 30, 2020 at 3:50 pm #6412
Thanks Jeremy! I really appreciate it. That seems to be working well.
- You must be logged in to reply to this topic.