Property '0' of undefined on second load of same resource

I have a setup just like the blocks set up here: Blocks of trials and counterbalancing — PsychoPy v2021.1

However, it kept saying “Error when loading resource, cannot read property ‘0’ of undefined” for the second xlsx so I tried it with one row, reading the same excel twice and it came up with the same error even after successfully running through the first block with the same excel file. Any ideas? The console does not give a line number for the error. I’ve tried several work arounds but it’s been fruitless. Please help.

Would the resource be a video file?

No, it’s just an excel file, the stimuli in the excel are just text

Are you using .pop()?

Please could you upload the minimal version or share a run link for the experiment?

Yes, I’m using .pop().

It’s creating an array, randomizing the excel rows and feeding that to the array and pushing one of the rows via .pop(). Then on a second block, I’m trying to feed to a second excel into the arrays to do the same thing over again with new stims. I’ll get it shared momentarily, but I do suspect it may not be an issue with the resource (excel file) but rather I need to reset the arrays? I don’t know how to do that, though. I’m using someone else’s file based on someone else’s file so it’s gotten a bit clunky with each addition. Here’s just the trouble spot:

// Make array for PM cues
// There are 9 PMs in each file
pmArr = [...Array(9).keys()];
util.shuffle(pmArr)

// make array for stimLoop
// There are 238 stimuli in each excel but I only need 216, in sets of 24
stimArray = [...Array(216).keys()];
util.shuffle(stimArray)

//Then in begin routine
// Get the next PM cue
pmRow = [];
val = pmArr.pop();
pmRow.push(val);

//Then in the begin routine of the inner loop
// Get 24 stim
currentArray = []
for (let i=0; i<24; i++) {
    currentArray.push(stimArray.pop())
}

So it goes through all that just fine on the first round, pulling in the stims and PMs from two different excels, then I have a large loop that starts that whole thing over with a new stims excel and a new PMs excel. But it spits the error about reading in the excel right at the start of the second round through the loop. I tried putting the alternate stims as secondary columns in the same excel and calling it twice, same error.

@wakecarter Here’s the public minimal version. Thanks for your time looking into this. If you run it, to advance the fixation cross, press space.

I can’t run it without making my own copy because it’s piloting.

I create several PM tasks every year. I preload my targets and fillers into separate arrays and then interleave them in the trials loop. However, I’ve only recently started using .pop().

I’ll make a dataless public copy of one of them tomorrow.

OOPS! Sorry about that. I actually just solved my problem. Silly error, I was thinking the arrays were resetting themselves where the code routine was located, not realizing it was in the “begin experiment” tab and therefore not part of the second loop through. Moving the array code from the earlier comment into the begin routine section of the routine just inside the loop of interest solved the issue. Thank you again for your time and suggestions.

1 Like

I’ve just updated my demo list with PM Time (featuring event and time based PM tasks).