| Reference | Downloads | Github

RangeError: Invalid array length

URL of experiment: Sign in · GitLab
The session 2 version also has the same issue: Sign in · GitLab

Description of the problem:

  • when importing condition: 1_B_Session1.csv
  • RangeError: Invalid array length

The experiment runs through the practice but once it tried to start the experimental trials is comes up with the above issue. It uses the same csv file in the practice and experimental trials so I am unsure why it now has an issue importing it.

Using PsychoPy version: 2020.1

1 Like

I am also having the same problem. I get the following error:

  • when importing condition: Group3.csv
  • RangeError: Invalid array length

URL of my experiment:
Psychopy version: v2020.2.5

I’d really appreciate a solution :slight_smile:

Hi Ryan, My issue was to do with what rows I was asking it to use - the rows did not fit with the files I was using. So maybe double check the rows it is trying to use for Group3.csv

Thanks, Laura. I think you are right that it’s related to row selection but the problem is that my experiment works in psychopy but not pavlovia.

I think the problem relates to the fact that the loop that ‘calls’ my .csv sheet picks trials based on what I’ve specified in the “selected rows” option of the loop, where I specify a variable that I created called “WhichRows”. “WhichRows” changes based on the block, e.g., I select rows 1-11 in the first block…


if BlockLoop.thisRepN <1:
WhichRows =list(range(0,11))


   if ((BlockLoop.thisRepN <1)) {

WhichRows = list(range(0, 11));

Given it works in psychopy but not pavlovia, can anyone suggest a reason why?

Have you tried asking it to report what WhichRows is setting itself to?

In the pavoliva code you have a space before the 11 which you don’t in the pavoliva code, maybe that is important?

also my rows are set like: 0:11, so maybe try than rather than creating a list?

Thanks again, Laura!

  • I’m a novice with Java so I rely on the Auto-JS conversion and then editing parts if necessary. So I don’t know how to ask it to report what WhichRows is setting itself to (however, the fact WhichRows works in psychopy probably means that the 0 and 11 is not problematic).

  • I tried removing the space (didn’t do anything) and then I tried using

WhichRows = range(0,11)

and I got the same error as above.

  • I also tried doing WhichRows = range(0:11) but the experiment could not initialize then.

Any other ideas?

I’m not sure why you are putting range before it, I just use 0:11, so:

WhichRows = 0:11

To get the experiment to report stuff I code I use the java code:

psychoJS.experiment.addData(“WhichRows”, WhichRows);

hmm, it doesn’t seem to like using WhichRows = 0:11
The psychopy runner provides the error: ERROR: Line 436: Unexpected token : in Mairead_v5.js
…and that line is the WhichRows line in the following:

if ((BlockLoop.thisRepN < 1)) {
WhichRows = 0:11;
NoLoopsAdapters = 27;
} else {

Is there an obvious difference there from your code? (note lines 2 and 3 are indented in the real script and I’ve excluded the rest of the else statement from here as I dont think its relevant - the problem is the WhichRows part I think)

I don’t set rows by code, I set them in a CSV file. So each loop reads a different row of the csv file.

I’m not sure what is wrong with your code, does it work if you just state the row to 0:11 rather than use a variable. I’m afraid I’m at the end of my limited knowledge.

Ok, thanks very much anyway Laura. Now that we’ve narrowed things down, I’d like to clarify my problem in case others have ideas :

My routine, AdapterWords (see image), is linked to the Group3.csv file which has 22 rows. In the first BlockLoop, I want to read only the first 11 of those rows, but in later blocks I want it to read rows 12-22. To control this, I created a variable called WhichRows, which you can see is written under “Selected Rows” for the AdapterWords routine. Crucially, WhichRows needs to be set before this routine and I do this by creating a previous routine called “SelectRowCode” which contains code such as:

if ((BlockLoop.thisRepN < 1)) {
WhichRows = range(0, 11);

This works in psychopy such that one loop of the AdpaterSelecter loop will loop through rows 0-11 of the group3.csv sheet. But pavlovia gives the following error:

@laura_prosser we were nearly there…after reading this thread (ReferenceError: slice is not defined), I tried this:

Psychopy code:

if NumberBlocks < 1:
WhichRows =“0:11”
NoLoopsAdapters = 27

Auto JS:

if ((NumberBlocks < 1)) {
WhichRows = “0:11”;
NoLoopsAdapters = 27;

This works in both psyhcopy and pavlovia! So the crucial thing is the quotation marks (note I dont advise copy pasting those quote marks - actually type them yourself otherwise it doesnt work). Thanks for pushing me in the correct direction, Laura :smiley:

1 Like