Counterbalance Routine

I’ve been testing the counterbalance routine.

It appears that if you have any code components with code set to Begin Experiment, this code appears prior to the code generated by the counterbalance routine.

If you have any code in the code components that relies upon the counterbalancing (like changing stimuli based on group) if you set this code to Begin Experiment you get a variable is undefined error. You can fix this if you have your code components early in you experimental flow set to Begin Routine.

I dont know if this is intentional, but I did find it a bit unintuitive.

Many thanks

While not perfect, it is understandable. The routines don’t execute until the experiment starts, which is after all of the Begin Experiment code has run. You can’t use information from the shelf for counterbalancing until Begin Routine of the routine after the counterbalance routine at the earliest.

Think of the Counterbalance Routine like any other Routine - it happens at the point in the Flow where it is. You can actually place it later in the experiment, which is useful if e.g. you want participants to only be assigned a group (and the group counter be decremented) if they accept the consent form.

We’ve talked about adding a “Code Routine” in the past, to make it more explicit when code happens (rather than a Code Component in a Routine executing code at experiment start), which might help here as you’d be able to see on the flow where the Begin Experiment code is happening. Ultimately we decided against it as the presence of both a Code Component and Code Routine in the “Components” panel could be confusing, plus you can already make essentially a Code Routine by having a Routine with one Code Component with the code you want in Begin Routine. Still open to the idea though, if there’s significant demand for it :slight_smile: