# I cannot successfully use counterbalance

**URL:** <https://discourse.psychopy.org/t/i-cannot-successfully-use-counterbalance/44928>\
**Category:** Online experiments\
**Created:** [May 28, 2025, 12:48pm UTC](https://discourse.psychopy.org/t/i-cannot-successfully-use-counterbalance/44928 "2025-05-28T12:48:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yiannis](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/yiannis/32/35056_2.png) [@Yiannis](https://discourse.psychopy.org/u/Yiannis)\
**Post date:** [May 28, 2025, 12:48pm UTC](https://discourse.psychopy.org/t/i-cannot-successfully-use-counterbalance/44928/1 "2025-05-28T12:48:20Z")

</div>

**OS** : Linux  
**Version** : 2024.2.5  
**Do you want it to also run locally? (y/n)** Both  
Hi,  
I cannot use successfully PsychoPy’s counterbalance component and Shelf’s counterbalance feature for either locally run exps or online.

Below screengrabs of how my exp looks like and shelf’s counterbalance contents.

I run the exp offline, I add a `print(counterbalance.group)` statement and it throws the error that counterbalance is not defined.

I run the exp online and no “slots” are taken from any of the groups.  
I open the data files and there is nothing relevant regarding counterbalance.

What am I doing wrong?  
Any pointers/advice will be much appreciated.  
Thanks

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/b/abbaab4f381d54b71fa135a4a7e53bc4482b2358.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/a/6a2f3039bffee2c7e0155168d947b628457b1e66.png)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [May 28, 2025, 12:50pm UTC](https://discourse.psychopy.org/t/i-cannot-successfully-use-counterbalance/44928/2 "2025-05-28T12:50:46Z")

</div>

> [@Yiannis](#):
>
> I run the exp offline, I add a `print(counterbalance.group)` statement and it throws the error that counterbalance is not defined.

Where are you doing this? You need to query counterbalance.group in Begin/End Routine after the counterbalance routine, not Begin Experiment.

---

<div class="post-metadata">

**Author:** ![Yiannis](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/yiannis/32/35056_2.png) [@Yiannis](https://discourse.psychopy.org/u/Yiannis)\
**Post date:** [May 28, 2025, 1:11pm UTC](https://discourse.psychopy.org/t/i-cannot-successfully-use-counterbalance/44928/3 "2025-05-28T13:11:30Z")

</div>

EDIT: scratch that - I forgot to insert it in the Flow 😤

It’s in the Begin routine in the trial routine

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/a/cafdff152b2ed6a598eaab88b0b1513a47a683cd.png)
