psychopy.org | Reference | Downloads | Github

Getting the error /* Syntax Error: Fix Python code */ while compiling to js when I use "global" in my python code

Hi everyone. I have a custom code in my experiment and this is the code:

LIST2=[standard,standard,devient]

count1=0
count2=0
count3=0

maxRes = 10
seqs = 30

def findDev(l):
    return l.index(devient)

def check(maxRes,l):
    global count1,count2,count3
    shuffle(l)
    d = findDev(l)
    if(d == 0):
        if(count1 < maxRes):
            count1 += 1
            return l
        else:
            return check(maxRes,l)
    elif(d == 1):
        if(count2 < maxRes):
            count2 += 1
            return l
        else:
            return check(maxRes,l)
    else:
        if(count3 < maxRes):
            count3 += 1
            return l
        else:
            return check(maxRes,l)

for i in range(0,seqs):
    check(maxRes,LIST2)

But I get the error /* Syntax Error: Fix Python code */ when it want to compile it to javascript. and it seems the global is the problem. What should I do to make it translate this piece of code to js?

In the Code component, what do you have the language set as? Is it set to just JavaScript or to auto translate?

It was set to auto translate. I found out the “global” in python code was the culprit. So I removed it and after translation, I set the language to “both” and then added “global” again to .py code.
Thank you.