RangeError: invalid array length | Are variables carried over between loops?

URL of experiment:

Description of the problem:


Our problem may concern local versus global variables in javascript. The following code works in the Python version of Psychopy, but in javascript we get undefined variables that lead to an “invalid array length” (presumably length ==0) when importing a conditions file.

What we are trying to do is control an inner loop using variables provided by an outer loop. In particular, when using the import conditions file in the inner loop, we are using the outer loop to provide the row numbers of the inner conditions file. thus, the outer loop provides (from its conditions excel file) variables called startBlockRow and endBlockRow. Our goal is to read from the inner conditions file only those rows startBlockRow to endBlockRow inclusively. We have made a little bit of javascript to create a variable called listOfRows just before the import conditions step; this variable listOfRows is created by a bit of code as follows:

var listOfRows = ;

for(let i2 = startBlockRow; i2>= endBlockRow; i2++){



The javascript crashes when it is trying to import conditions for the inner loop. When we look at the variables in the console, neither listOfRows nor i2 are defined. We believe that this is because these two variables are defined in one routine, but they are used to define the activity of a loop that occurs after the routine is completed. We suspect that because each routine is structured as a javascript function, variables defined in one routine are local variables that are not passed to the import controller for the inner loop that occurs after the defining routine has ended (i.e. our local variables are not part of the “snapshot” variable).

Could this be our problem in javascript, and would the solution entail some way of making the import control variables global variables? Currently this way of controlling the inner loop using a previous routine works fine in the Python version of the experiment.