OK, thanks, the credits have been restored now.
If the default value is set in the expinfo dialogue box (e.g. session = 001 as above), will having “session = {{%SESSION_ID%}}” in the hyperlink override this? Similarly, could I set STUDY_ID to, say, 42 in the expinfo to differentiate non-Prolific from Prolific participants?
Thanks!
Deborah.
UPDATE: My student has reset the URL at Prolific as set out above (she had to quit and duplicate the study, as Prolific won’t let you reset it once the study is launched), but now she is getting the same error as before - “RangeError: Invalid array length”.
Could you PLEASE let me know what is going on here?
Edited to add that I have tried this myself - the experiment loads OK, and the first half goes well, but then it crashes immediately after the “progress bar”, so I KNOW it is something to do with the group allocations. (As a reminder, this is where the “feedback” on their performance is presented; group 1’s loop repeats are set to 2-group (so this feedback does not appear for group 2), and group 2’s are set to group -1 (so that they will not appear for group 1)).
Edited for further info: Examining the Javascript console shows this:
The code is here and I have set it to internal:
Thanks
Deborah.
If you create a new study on GitLab then you need a new shelf entry. The shelf entry must be a list with one more zero than the number of groups. (Or the current values from the previous version if you want the new study to know about the existing imbalance)
Hi Wake,
No, it’s the SAME STUDY on GitLab. It’s just a new project in Prolific.
The GitLab study is exactly the same.
Please can you work out what is wrong with the code?
Thanks
Deborah.
If it crashes after progress bar then it is probably due to an invalid value for group which can’t be interpreted for the number of repetitions.
I recommend that you add print("group = ", group) immediately after expInfo["group"] = group # Add group allocation to data file in code_3 so you can see the value in Developer tools without having to go through the card sorting task.
Please also add print("availableGroups = ", availableGroups, " from ", groupAllocations) and print("minAllocation = ", minAllocation) at the same point.
Once these are added, please let me know and I’ll test it to look at the values in Developer Tools. Please could you also check that the shelf entry is called group_allocations and that the first number in the list isn’t the smallest. [26 8 18] and [6 6 18] is fine, but if you reset it to something like [6 8 18] it will break.
OK, all done as instructed. Yes the shelf is still [26 8 18] and is still called group_allocations, .
I had also concluded that the group number is invalid. While piloting we were able to fix it by resetting all the shelf values to 0. I thought this was due to repeated participant numbers, but have since realised we’re not tracking those.
Cheers
Deborah.

Please could you add the following to the Begin Experiment tab of code_3 and let me know so I can try again?
group = 0
minAllocation = 0
Thanks. I think I’ve located the source of the bug. Please try changing
minAllocation = Math.min(groupAllocations);
to
minAllocation = Math.min(...groupAllocations);
The error was in the code in my tip (now edited) but the tip already had the fix as a comment.
# … needed to indicate groupAllocations is a list
I also note that this code sets the first value to expInfo[‘session’] which will overwrite the value of session from Prolific.
Hi Wake,
Unfortunately that does not seem to work. It’s set to autoJS, but if I try to change the Python code on the left, the JS code throws an error and says “Fix Python code”.
Any further ideas? Should I change it to a “both” code component, or JS only since I’m not running it locally?
Yes I had realised about the “session” value; I might include another field in the expinfo for the Prolific session ID.
Thanks
Deborah.
Thank you. That post has alerted me to a mistake I made when I added local counterbalancing to my working online counterbalance code.
The … should only appear on the JS side, which means that that section of code should be in the Both component.
Begin Routine on the Python side should be
if os.path.exists(allocations_file):
try:
with open(allocations_file, 'r') as f:
groupAllocations = json.load(f)["group_allocations"]
except Exception as e:
logging.warning(f"Warning: Could not load group allocations ({e}), starting fresh.")
groupAllocations = []
else:
groupAllocations = []
if len(groupAllocations):
expInfo["session"] = groupAllocations[0] # Add session number to data file
minAllocation = min(groupAllocations)
else:
expInfo["session"] = 0
minAllocation = 0
groupAllocations = [0]
and on the JS side it should be
groupAllocations = await psychoJS.shelf.getListValue({key: ["group_allocations"], defaultValue: []}); // Get values
if (groupAllocations.length) {
expInfo["session"] = groupAllocations[0];
minAllocation = Math.min(...groupAllocations); // ... needed in JS to indicate groupAllocations is a list
} else {
expInfo["session"] = 0;
minAllocation = 0;
groupAllocations = [0];
}
Hopefully that will sort it. When you’ve made that change I’ll be happy to check the print statements again.
And presumably, that section comes out of the auto-JS code?
OK, done, could you please check?
Thanks!
Deborah.
There’s a syntax error. You’ve got
groupAllocations = await psychoJS.shelf.getListValue({key: ["groupAllocations = await psychoJS.shelf.getListValue({key: ["group_allocations"], defaultValue: []}); // Get values
on the JS side instead of
groupAllocations = await psychoJS.shelf.getListValue({key: ["group_allocations"], defaultValue: []}); // Get values
Not sure how that happened since I copied & pasted your code directly from here.
However, I’ve fixed that now, can you try again?
Did you accidentally delete availableGroups = [] # Define list from the top of the Auto component? It should be:
availableGroups = [] # Define list
for Idx in range(1, numberOfGroups + 1):
if len(groupAllocations) == Idx:
groupAllocations.append(0)
availableGroups.append(Idx)
elif not groupAllocations[Idx]:
groupAllocations[Idx] = 0
availableGroups.append(Idx)
elif groupAllocations[Idx] < (minAllocation + maxAllocationGap):
availableGroups.append(Idx)
shuffle(availableGroups)
group = availableGroups[0] # group takes positive integer values
expInfo["group"] = group # Add group allocation to data file
plus the print statements
I didn’t think I had, but have fixed now.
Thanks again.
Looking good.
It’s ready for you to test.
Fantastic. Just one more quick question - I need a second non-completion URL for participants who don’t meet the inclusion criteria - there’s a different one if they don’t consent which I have in the Settings, but that only allows for one non-completion URL. If they don’t meet the inclusion criteria they should apparently still get paid a small amount, and we have already had complaints about this.
So I’ve added a line in the “end routine” section of the exclusion code routine:
if ((surveyResponse['block_1/Mental_health_conditions'] !== "0")) {
psychoJS.experiment.nextEntry();
psychoJS.setRedirectUrls("https://app.prolific.com/submissions/complete?cc=C14NST0J", "https://app.prolific.com/submissions/complete?cc=CLILLGR8");
return psychoJS.quit({message: 'Thank you for your participation.', isCompleted: false});
}
Before I commit the changes, will this break anything? And will it work?
Thanks!
Deborah.
That looks fine, except that it will ignore STUDY_ID “42”, so you might want to include a nested if STUDY_ID not equal to “42” around the redirect code.
if ((surveyResponse["block_1/Mental_health_conditions"] !== "0")) {
psychoJS.experiment.nextEntry();
if ((expInfo["STUDY_ID"] !== "42")) {
psychoJS.experiment.setRedirectUrls("https://app.prolific.com/submissions/complete?cc=C14NST0J", "https://app.prolific.com/submissions/complete?cc=CLILLGR8");
}
return psychoJS.quit({message: "Thank you for your participation.", isCompleted: false});
}