psychopy.org | Reference | Downloads | Github

Syntax error from autoJS

I have used the custom code to add python commands to randomise the order etc.


trialListCatA = list(range(2,6))
trialListCatB = list(range(6,8))
trialListCatC = list(range(8,20))
trialListCatD = list(range(20,26))
trialListCatE = list(range(26,38))
trialListCatF = list(range(38,42))
trialListCatG = list(range(42,68))

random.shuffle(trialListCatA)
catAsliceBL2 = trialListCatA[0:3]
catAsliceBL3 = trialListCatA[3:4]

random.shuffle(trialListCatG)
catGsliceBL2 = trialListCatG[0:15]
catGsliceBL3 = trialListCatG[15:26]

trialListBlock1 = trialListCatA + trialListCatB
trialListBlock2 = trialListCatC + trialListCatD + catGsliceBL2 + catAsliceBL2
trialListBlock3 = trialListCatE + trialListCatD + trialListCatB + trialListCatF + catGsliceBL3 + catAsliceBL3
trialListBlock4 = trialListCatA + trialListCatB```

The python commands work fine however when converted to JS in the autoJS I get a syntax error in line 12

        ```// add-on: list(s: string): string[]
        function list(s) {
            // if s is a string, we return a list of its characters
            if (typeof s === 'string')
                return s.split('');
            else
                // otherwise we return s:
                return s;
        }
        
        import * as random from 'random';
var catAsliceBL2, catAsliceBL3, catGsliceBL2, catGsliceBL3, trialListBlock1, trialListBlock2, trialListBlock3, trialListBlock4, trialListCatA, trialListCatB, trialListCatC, trialListCatD, trialListCatE, trialListCatF, trialListCatG;
trialListCatA = list(range(2, 6));
trialListCatB = list(range(6, 8));
trialListCatC = list(range(8, 20));
trialListCatD = list(range(20, 26));
trialListCatE = list(range(26, 38));
trialListCatF = list(range(38, 42));
trialListCatG = list(range(42, 68));
random.shuffle(trialListCatA);
catAsliceBL2 = trialListCatA.slice(0, 3);
catAsliceBL3 = trialListCatA.slice(3, 4);
random.shuffle(trialListCatG);
catGsliceBL2 = trialListCatG.slice(0, 15);
catGsliceBL3 = trialListCatG.slice(15, 26);
trialListBlock1 = (trialListCatA + trialListCatB);
trialListBlock2 = (((trialListCatC + trialListCatD) + catGsliceBL2) + catAsliceBL2);
trialListBlock3 = (((((trialListCatE + trialListCatD) + trialListCatB) + trialListCatF) + catGsliceBL3) + catAsliceBL3);
trialListBlock4 = (trialListCatA + trialListCatB);```

@smoha005, I think it would be a good idea to highlight, or present separately, the line causing the problem, it is not obvious which line is line 12.

@dvbridges
I have put line 12 below:
import * as random from 'random';

Is coming up as syntactically invalid from the autoJS function. I’m not sure how to correct it.
I would really appreciate your help. Thank you.