| Reference | Downloads | Github

ReferenceError: slice is not defined

URL of experiment:

Description of the problem: I write prospective memory experiments by reading the targets and fillers into separate arrays and then interleaving them.

To keep things simple for the student, I ask for all the stimuli to be in the same csv file, which means that I have to use slice to extract the targets, because there are always fewer targets than fillers.

My target_loop has $slice(0,10) at the selected rows, which I think is the only instance of slice used in my template experiment. In the Javascript, this has translated to:

trialList: TrialHandler.importConditions(psychoJS.serverManager, 'items.xlsx', slice(0, 10)),

Interestingly, when searching for slice I discovered PsychoPy had translated

    elif 'backspace' in keys:
        captured_string = captured_string[:-1]
    elif 'delete' in keys:
        captured_string = captured_string[:-1]


 else {
        if (_pj.in_es6("backspace", keys)) {
            captured_string = captured_string.slice(0, (- 1));
        } else {
            if (_pj.in_es6("delete", keys)) {
                captured_string = captured_string.slice(0, (- 1));

but I’m assuming this isn’t the issue.

Best wishes,


“slice()” doesn’t exist in JS, array.slice() and string.slice() do. I think the way importConditions works in JS, it just doesn’t work that way. You may have better luck with alternative syntax, like [0:10].

See for examples of different ways of pulling specific conditions.

The reason I use slice is because I can’t get other syntax to work in PsychoPy (standalone).

slice(0,10) works [0:10] gives Python syntax error in field Selected Rows when trying to set the loop
[0:10] gives TypeError: ‘NoneType’ object is not iterable when starting the experiment
[0,10] gives IndexError: list index out of range when trying to set the position of the first target

$[0,10] works in standalone but gives TypeError: Cannot read property ‘push’ of undefined online. The error is in the line targetlist.push(Target);

I’ve just followed your PsychoPy link and realised that $[0,10] will only load two targets, not ten.

0:10 (no brackets) seems to work, in that it’s fine locally but I still get the TypeError as above.

Best wishes,


That’s unexpected. @jon you know this import system better than I do, any thoughts?

@wakecarter do you have any experience reporting issues on GitHub? The fact that the import syntax isn’t working is worth reporting as a bug:

If you don’t feel comfortable with that I can also do it.

I’m not surprised that using $slice() doesn’t work. slice is a class in Python but it’s a method in JS. And I don’t think we need to worry about the problem with import in general as this is about the importConditions function.

What it really needs is for the importConditions in the JS lib to handle strings and treat them as slices in the same way as the Python code. So that simply writing 0:10 in the selectedRows box works!

Just to follow up on this. What is the correct way to select rows that could work for both standalone and pavlova?


I’ve just tested the format 0:10 for the first ten rows.

That can be set up in code as a variable userows=“0:10” and then used with the dollar $userows.

Best wishes,


1 Like

I have it setup exactly like that and it still uses all the files in the csv for me. Any ideas?

hi @wakecarter and thx as usual for your insights!
I have the following issue with my experiment (

I need to select 16 trials from a .xlsx file of 120. The trials should be selected according to the following strategy:

  • 4 trials randomly chosed among the rows 0 and 29;
  • 4 trials randomly chosed among the rows 30 and 59;
  • 4 trials randomly chosed among the rows 60 and 89;
  • 4 trials randomly chosed among the rows 90 and 119.
    To do this I wrote this JS piece of code in the Begin Experiment:
var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
    container["in_es6"] = in_es6;
    return container;
_pj = {};

jump_routine = 0;

bgn = 0;
fnl = 29;
d = 4;
idx = (fnl + 1);

function ri_norep(ini, fin, delta) {
    var list, r;
    list = [];
    for (var i = 0, _pj_a = delta; (i < _pj_a); i += 1) {
        r = (Math.floor((Math.random() * ((fin - ini) + 1))) + ini);
        if ((! _pj.in_es6(r, list))) {
    return list;
td1 = ri_norep(bgn, fnl, d);
td2 = ri_norep(idx, (fnl + idx), d);
asd1 = ri_norep((2 * idx), (fnl + (2 * idx)), d);
asd2 = ri_norep((3 * idx), (fnl + (3 * idx)), d);
order = td1.concat( td2, asd1, asd2);
thisExp.addData("trial_order", order);

k_rtn = event.getKeys();

I also wrote $order in the Selected rows of the loop GUI, as depicted here:

In pavlovia it works until the 10th trial. After that the stimulus/video is not played anymore and no error is shown in the Console . When less trials are run, 4 or 8, all goes as it should be: the experiment stops when all trials are finished.
I tested the experiment on different machines and I have a similar issue: at a certain trial stimuli/video are not played anymore.

The size of the resource folder is ~800 MB, I hope it is not a matter related to the big folder dimensions.
If someone of you has a suggestion, I’ll appreaciate it. Thanks a lot!