# P5.Score: Cannot read property 'start' of undefined

**URL:** <https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305>\
**Category:** Libraries\
**Created:** [November 7, 2019, 1:05pm UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305 "2019-11-07T13:05:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![m4rinos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/m4rinos/32/7032_2.png) [@m4rinos](https://discourse.processing.org/u/m4rinos)\
**Post date:** [November 7, 2019, 1:05pm UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/1 "2019-11-07T13:05:56Z")

</div>

Hi, I’m new to this community and p5 so forgive me if I ask something silly, but here is my problem.

I have a part with a phrase and I’m now trying to add the part to a score because I want to be able to play more parts later on. When I play the part by itself it works, but playing the score with that part does not work and triggers

`Uncaught TypeError: Cannot read property 'start' of undefined (sketch: line 34)`

I’m not sure what I do wrong, I initiate a new score with my part “preroll”:

`score = new p5.Score(preroll);`

and start it with:

`score.start();`

My whole code can be viewed at: [https://editor.p5js.org/m4rinos/sketches/HFYqbDM2b](https://editor.p5js.org/m4rinos/sketches/HFYqbDM2b)

any help would be greatly appreciated 🙂

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 7, 2019, 5:12pm UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/2 "2019-11-07T17:12:21Z")

</div>

> [@m4rinos](#):
>
> _**Uncaught TypeError: Cannot read property ‘start’ of undefined (sketch: line 34)**_

Looking at browser’s own console (F12), the error doesn’t occur in your own code but inside the p5.sound library itself! 😮

More precisely inside p5.Score::**start()** method: 🎼

> <https://github.com/processing/p5.js/blob/0.10.2/lib/addons/p5.sound.js#L10858-L10861>

Seems like its _parts[]_ array is completely empty! 😲

After perusing p5.Score’s constructor here: 🧐

> <https://github.com/processing/p5.js/blob/0.10.2/lib/addons/p5.sound.js#L10824-L10840>

I highly doubt the expression `if (arguments[i] && this.parts[i]) {` could ever become `true`. 🤔

B/c _parts[]_ starts empty: `this.parts = [];`. 😳

And therefore, all its indices are still `undefined`; so the condition will always be `false`! 🤪

---

<div class="post-metadata">

**Author:** ![m4rinos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/m4rinos/32/7032_2.png) [@m4rinos](https://discourse.processing.org/u/m4rinos)\
**Post date:** [November 8, 2019, 5:00am UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/3 "2019-11-08T05:00:49Z")

</div>

Hey thanks for the investigative work!

So yes, if I understand correctly my part in `score = new p5.Score(preroll);` is not loaded at all. Looking at the main Score function `p5.Score = function() {` it does not seem to take any parameters to fill the `this.parts = [];` array, so we might just need to add a parameter for **parts** right? Something like:

```auto
p5.Score = function (parts) {
    // for all of the arguments
    this.parts = parts;
    this.currentPart = 0;
    var thisScore = this;
    for (var i in arguments) {
      if (arguments[i] && this.parts[i]) {
        this.parts[i] = arguments[i];
        this.parts[i].nextPart = this.parts[i + 1];
        this.parts[i].onended = function () {
          thisScore.resetPart(i);
          playNextPart(thisScore);
        };
      }
    }
    this.looping = false;
  };

```

Do you know how to take this from here?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 8, 2019, 5:11am UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/4 "2019-11-08T05:11:39Z")

</div>

You should open an issue on its repo: 🐙

> **[processing/p5.js-sound](https://github.com/processing/p5.js-sound/issues)**
>
> p5.sound brings the Processing approach to Web Audio and p5.js. Demos: - processing/p5.js-sound

In the interim, you might try to replace the p5.Score’s current bugged constructor w/ a working 1. 🐛

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [November 12, 2019, 1:03am UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/5 "2019-11-12T01:03:19Z")

</div>

@m4rinos – Was this ever opened as an issue on the repo?

---

<div class="post-metadata">

**Author:** ![m4rinos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/m4rinos/32/7032_2.png) [@m4rinos](https://discourse.processing.org/u/m4rinos)\
**Post date:** [November 18, 2019, 11:55am UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/6 "2019-11-18T11:55:19Z")

</div>

My apologies, I was on a trip.I now filed an issue at Github (~~[issue 391](https://github.com/processing/p5.js-sound/issues/391)~~ [issue398](https://github.com/processing/p5.js-sound/issues/398)).  
In the mean time, you can change

`if (arguments[i] && this.parts[i]) {`

to

`if (arguments[i]) {`

to locally to fix the problem. `this.parts` is only filled after the condition, so it never gets there.

---

<div class="post-metadata">

**Author:** ![candyflopper](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@candyflopper](https://discourse.processing.org/u/candyflopper)\
**Post date:** [January 25, 2020, 2:20pm UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/7 "2020-01-25T14:20:30Z")

</div>

Hiya m4rinos!  
I’m currently having similar issues with p5.score ☹  
Did you ever find the solution to ur issue?

---

<div class="post-metadata">

**Author:** ![m4rinos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/m4rinos/32/7032_2.png) [@m4rinos](https://discourse.processing.org/u/m4rinos)\
**Post date:** [January 26, 2020, 6:03am UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/8 "2020-01-26T06:03:41Z")

</div>

well, yes and no, I’ve created an issue at the repository, but in the mean time, I just hack the `p5.sound.js` file myself with the above change and that works. I did run into more issues later on when I tried to do more complicated stuff so I ended up organising my own parts, but this should get you going if all you need is a container for your parts. Of course be aware that updating your package will overwrite your changes so you might want to either not update or self host.

---

<div class="post-metadata">

**Author:** ![mikhaelMltplx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikhaelmltplx/32/10300_2.png) [@mikhaelMltplx](https://discourse.processing.org/u/mikhaelMltplx)\
**Post date:** [August 18, 2020, 6:25pm UTC](https://discourse.processing.org/t/p5-score-cannot-read-property-start-of-undefined/15305/9 "2020-08-18T18:25:53Z")

</div>

Hello,

is there any new (easy to follow) solution? or maybe an official update to come?

@m4rinos, can you share your “hacked” p5sound lib file, please?

thank you!
