Counterbalancing error in online experiment

Hi everyone.

I’m having trouble with counterbalancing in the online version of my experiment. Even though the code I wrote for counterbalancing worked in Psychopy locally (in Python), it fails to convert to Javascript so it can’t be uploaded to Pavlovia.

I have 2 different counterbalances in my experiment. Both counterbalances place the random half of the participants in one condition and the other half in the other condition. And participants are supposed to see different instructions in these conditions, so it’s not a counterbalance simply for order but for different types of instructions.

Here are the screenshots of the codes that make this possible:

I created 2 different code components in the Begin Experiment frame to place participants into these conditions. And I have 4 excel files for the different group conditions: group_A.xlsx, group_B.xlsx, group_1.xlsx, and group_2.xlsx which connect to the excel files through loops I created for counterbalancing.

The codes for counterbalancing are the following:
2022-09-15 (16)
2022-09-15 (18)

The curious issue is that this code works in Python/Psychopy without problem, but when I try to compile the experiment into JS code, I stumble with an error that says “selectGroup” is not defined.

If anyone has an idea about what might cause this, I’d highly appreciate your insights. Thank you.

Your code looks fine. The only difference I see to what I usually do is that you run some code in the Conditions field. What I do, is already do that in the if-statement itself. Maybe that works for you:

if(Math.random() >= .5){
    ConditionsFile1 = "group_1.xlsx"    
    ConditionsFile1 = "group_2.xlsx" }

Then, use $ConditionFile1 in the Conditions field of the respective loop.

1 Like

Thank you for your help and fast response and apologies for the late reply!
I changed the code in your way and it was able to compile to JS and got uploaded to Pavlovia but I couldn’t pilot the study at first because it gave some javascript errors but after solving those problems the code really worked on Pavlovia as well! I don’t know why “selectGroup” causes trouble but thank you so much for your help!

Great, that it works! I made a minimal example to get some closure. It shows that your approach should actually have worked. So, no idea of what the error might have been :smiley:

Thanks again! :slight_smile: