# InternalError: too much recursion

**URL:** <https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287>\
**Category:** Online experiments\
**Created:** [April 14, 2021, 3:00pm UTC](https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287 "2021-04-14T15:00:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhaleh](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@Zhaleh](https://discourse.psychopy.org/u/Zhaleh)\
**Post date:** [April 14, 2021, 3:00pm UTC](https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287/1 "2021-04-14T15:00:28Z")

</div>

URL of experiment: [https://run.pavlovia.org/Zhaleh/fullexperiment/html](https://run.pavlovia.org/Zhaleh/fullexperiment/html)

Description of the problem: I use builder view and have a custom code in it that shuffle the list of numbers that need to be presented to participants. I’ve recently changed my code in order to counterbalance trials in my experiment. Here is the code:

```auto
def shuffle_list(List):
    counta=0
    countb=0
    countc=0
    for ii in List:
        shuffle(ii)
        d = difFinder(ii)
        if(d == 1):
            counta += 1
        elif(d == 2):
            countb += 1
        elif(d == 3):
            countc += 1
    if(counta == countb and counta == countc):
        shuffle(List)
        return List
    else:
        return shuffle_list(List)
    
def difFinder(i):
    if i[0] != i[1] and i[0] != i[2]:
        return 1;
    if i[1] != i[0] and i[1] != i[2]:
        return 2;
    if i[2] != i[0] and i[2] != i[1]:
        return 3;

```

While running locally it’s ok but online, it gives this error:  
InternalError: too much recursion  
How can I fix the code to prevent this error?  
Thank you for your help.

---

<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:** [April 14, 2021, 4:34pm UTC](https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287/2 "2021-04-14T16:34:02Z")

</div>

I recently learned that for def to work in an auto translate code component online, it needs to go in a Before Experiment tab.

---

<div class="post-metadata">

**Author:** ![Zhaleh](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@Zhaleh](https://discourse.psychopy.org/u/Zhaleh)\
**Post date:** [April 15, 2021, 2:33am UTC](https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287/3 "2021-04-15T02:33:04Z")

</div>

Hi @wakecarter . Thanks for your suggestion. I did what you just said but I get this error:  
TypeError: shuffle is not a function  
I didn’t have this problem when my codes were in begin experiment tab. I just moved whatever was in “begin experiment” to “before experiment”.

---

<div class="post-metadata">

**Author:** ![Zhaleh](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@Zhaleh](https://discourse.psychopy.org/u/Zhaleh)\
**Post date:** [April 15, 2021, 2:51am UTC](https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287/4 "2021-04-15T02:51:06Z")

</div>

And moving my codes to before experiment didn’t have any effect on this error of too much recursion.  
@sotiri Do you happen to know what should I do with this error? How can I fix it?

---

<div class="post-metadata">

**Author:** ![Zhaleh](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@Zhaleh](https://discourse.psychopy.org/u/Zhaleh)\
**Post date:** [April 15, 2021, 3:18am UTC](https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287/5 "2021-04-15T03:18:38Z")

</div>

And I should mention that the error while running the experiment in Chrome is like this:

- **RangeError: Maximum call stack size exceeded**  
Which I searched and found out that these are kind of the same errors.  
In my experiment, I really need to counterbalance the number of times the first list differs from the other two, the second list differs from the other two, and the third list differs from the other two.  
If you think I can achieve the same goal with another programming for this or by including a function or something in my jscode it would help me a lot.

---

<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:** [April 15, 2021, 5:54am UTC](https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287/6 "2021-04-15T05:54:57Z")

</div>

Have a look at my crib sheet for how to define shuffle in code\_JS

---

<div class="post-metadata">

**Author:** ![sotiri](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sotiri](https://discourse.psychopy.org/u/sotiri)\
**Post date:** [April 23, 2021, 4:20pm UTC](https://discourse.psychopy.org/t/internalerror-too-much-recursion/22287/7 "2021-04-23T16:20:05Z")

</div>

Hi @zhaleh, were you able to sort this one out? I get a 404 when I visit the GitLab repo, x
