Some tips on Shelf's CounterBalance


I have been playing with the new Shelf feature and specifically with the counterbalance part. Below some tips that may save you time during troubleshooting.

  1. It does not work with old-ish versions of PsychoPy e.g. 2022.1.4. If you get the error below then update to the newest version of psychopy e.g. 2022.2.2

  2. On the documentation it states that the snippet [thisGroup, finished] = await psychoJS.shelf.counterBalanceSelect({key: ['groups'], groups: ['A', 'B', 'C'], groupSizes: [10, 10, 10]}) will return the thisGroup and the finished.
    I have not managed to make this work; it will either return
    finished is not defined
    TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
    depending on whether you added the code component before or after the trials.
    What worked for me is the snippet below
    thisGroup = await psychoJS.shelf.counterBalanceSelect({key: ['groups'], groups: ['A', 'B', 'C'], groupSizes: [10, 10, 10]})
    (this can be found in the link “demo file” by @becca)

  3. To save the values of the group and the finished vars in your data use either dot notation or bracket and name e.g.
    psychoJS.experiment.addData("thisGroup.finished", thisGroup.finished);
    or (untested)
    psychoJS.experiment.addData("thisGroup.finished", thisGroup['finished']);
    psychoJS.experiment.addData("", thisGroup['group']);

  4. Do not place the component with the code snippet in 2 above inside a loop - it will give an error (object is not iterable)

I hope the above help.


Hi Yiannis,

I’m pleased to hear that you’re trying out the Shelf! And thanks for sharing your tips.

On the first point - shelf will not work with any release earlier than 2022.2 - this is because the functions required to interact with shelf are part of the 2022.2 release.