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

**URL:** <https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637>\
**Category:** Online experiments\
**Created:** [April 27, 2021, 9:09pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637 "2021-04-27T21:09:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ewiemers](https://avatars.discourse-cdn.com/v4/letter/e/ecccb3/32.png) [@ewiemers](https://discourse.psychopy.org/u/ewiemers)\
**Post date:** [April 27, 2021, 9:09pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/1 "2021-04-27T21:09:19Z")

</div>

I have a setup just like the blocks set up here: [Blocks of trials and counterbalancing — PsychoPy v2021.1](https://www.psychopy.org/builder/blocksCounterbalance.html)

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.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 27, 2021, 9:46pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/2 "2021-04-27T21:46:35Z")

</div>

Would the resource be a video file?

> [@Video stimuli not resetting to beginning in online experiment](https://discourse.psychopy.org/t/video-stimuli-not-resetting-to-beginning-in-online-experiment/10459/13):
>
> Couldn’t you do something like the following…? Begin Routine moviestarted=0 Each Frame if t \> .5 and moviestarted == 0: moviestarted = t myMovie.play() End Routine myMovie.stop() myMovie.seek(0) Best wishes, Wakefield

---

<div class="post-metadata">

**Author:** ![ewiemers](https://avatars.discourse-cdn.com/v4/letter/e/ecccb3/32.png) [@ewiemers](https://discourse.psychopy.org/u/ewiemers)\
**Post date:** [April 27, 2021, 9:50pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/3 "2021-04-27T21:50:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 27, 2021, 9:53pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/4 "2021-04-27T21:53:41Z")

</div>

Are you using .pop()?

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

---

<div class="post-metadata">

**Author:** ![ewiemers](https://avatars.discourse-cdn.com/v4/letter/e/ecccb3/32.png) [@ewiemers](https://discourse.psychopy.org/u/ewiemers)\
**Post date:** [April 27, 2021, 10:08pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/5 "2021-04-27T22:08:35Z")

</div>

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:

```auto
// 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.

---

<div class="post-metadata">

**Author:** ![ewiemers](https://avatars.discourse-cdn.com/v4/letter/e/ecccb3/32.png) [@ewiemers](https://discourse.psychopy.org/u/ewiemers)\
**Post date:** [April 27, 2021, 10:39pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/6 "2021-04-27T22:39:12Z")

</div>

@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.

> **[AMA Lab / PM\_Mini](https://gitlab.pavlovia.org/ama_lab/pm_mini/)**
>
> Minimum version for troubleshooting loop

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 27, 2021, 11:05pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/7 "2021-04-27T23:05:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ewiemers](https://avatars.discourse-cdn.com/v4/letter/e/ecccb3/32.png) [@ewiemers](https://discourse.psychopy.org/u/ewiemers)\
**Post date:** [April 27, 2021, 11:35pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/8 "2021-04-27T23:35:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 28, 2021, 4:04pm UTC](https://discourse.psychopy.org/t/property-0-of-undefined-on-second-load-of-same-resource/22637/9 "2021-04-28T16:04:35Z")

</div>

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

> [@PsychoPy Online Demos](https://discourse.psychopy.org/t/psychopy-online-demos/22319):
>
> If you have routines or experiments that are likely to be useful to others, please create a post in this thread, editing your post to add new demos so there is one post per creator. Ideally set your demos so they can be tested without consuming a credit (if you don’t have a site license) by adding a final routine that can’t end, disabling save incomplete results and adding a small number of credits. Please do not discuss the demos in this thread or create more than one post unless you have a la…
