# TypeError: Cannot read properties of undefined (reading '-5')

**URL:** <https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916>\
**Category:** Beginners\
**Created:** [August 9, 2024, 2:35pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916 "2024-08-09T14:35:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![JakobVirgil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jakobvirgil/32/19932_2.png) [@JakobVirgil](https://discourse.processing.org/u/JakobVirgil)\
**Post date:** [August 9, 2024, 2:35pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/1 "2024-08-09T14:35:40Z")

</div>

It gives line numbers like “at undefined:53042:53”  
The number ranges from 0 to -5 depending on the length of my code.  
here is the code

> **[cthfagin copy by a.king.ink -p5.js Web Editor](https://editor.p5js.org/a.king.ink/sketches/y0lSV5fTC)**
>
> A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 9, 2024, 3:28pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/2 "2024-08-09T15:28:26Z")

</div>

Have you copied and pasted the code from another editor?

It seems to me that you might have extra non-visible characters either at the line-ends or file-end.

I did get an undefined error of line 2 and when I deleted after the ; the sketch worked.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 9, 2024, 3:34pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/3 "2024-08-09T15:34:13Z")

</div>

BTW the game looks promising but I thought the the red dots very quickly became so fast I just gave up trying to touch the red dots.

---

<div class="post-metadata">

**Author:** ![JakobVirgil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jakobvirgil/32/19932_2.png) [@JakobVirgil](https://discourse.processing.org/u/JakobVirgil)\
**Post date:** [August 9, 2024, 3:53pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/4 "2024-08-09T15:53:57Z")

</div>

Thanks that is a convention in the genre.  
Make a game too hard to beat and then use upgrades until you can.  
I used JShint to clean some stuff up.  
So which ; do I have to delete?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 9, 2024, 4:34pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/5 "2024-08-09T16:34:37Z")

</div>

When I first tried it I got an error on line 2, I clicked behind the ; e.g.

![Screenshot 2024-08-09 at 17.23.48](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/c/3cfacd71c074d8357121b4b4f2eeb89a4c5a1c16.png)

Pressed the delete key (not the backspace) and it concatenated lines 2 & 3

![Screenshot 2024-08-09 at 17.31.28](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/b/3b689ee7d90255eb0fa39f479ba71ee3fad713ba.png)

Then I pressed the enter key to move line 3 back and bingo your game started.

The most likely culprit is the EOL (End-of-line character) because it can vary depending on the code editor / OS.

I have been playing your game - it’s quite addictive once you undrstand the game play. Well done 👍

---

<div class="post-metadata">

**Author:** ![JakobVirgil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jakobvirgil/32/19932_2.png) [@JakobVirgil](https://discourse.processing.org/u/JakobVirgil)\
**Post date:** [August 9, 2024, 4:38pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/6 "2024-08-09T16:38:28Z")

</div>

Thank you so much you are a mensch do you mind saving the change you made?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 9, 2024, 6:08pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/7 "2024-08-09T18:08:18Z")

</div>

> [@JakobVirgil](#):
>
> do you mind saving the change you made?

Just noticed this. The editor will not allow me to make changes to _ **another persons** _ sketch.

**Update**  
I have created a working copy [here](https://editor.p5js.org/quark-js/sketches/ym8tVQUCU)

---

<div class="post-metadata">

**Author:** ![JakobVirgil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jakobvirgil/32/19932_2.png) [@JakobVirgil](https://discourse.processing.org/u/JakobVirgil)\
**Post date:** [August 9, 2024, 6:13pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/8 "2024-08-09T18:13:00Z")

</div>

No worries  
I fixed it by clicking on “tidy code” I suppose that stripped off the hidden characters.

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [August 10, 2024, 12:00am UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/9 "2024-08-10T00:00:16Z")

</div>

This is a really cool game!

However, the icon for slow drops upgrade does not show.  
It just shows ⛛ .

---

<div class="post-metadata">

**Author:** ![JakobVirgil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jakobvirgil/32/19932_2.png) [@JakobVirgil](https://discourse.processing.org/u/JakobVirgil)\
**Post date:** [August 10, 2024, 12:14am UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/10 "2024-08-10T00:14:56Z")

</div>

I guess I chose the icon poorly LOL  
⛛is the one I picked

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 10, 2024, 9:20am UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/11 "2024-08-10T09:20:31Z")

</div>

I have been playing your game again very addictive - I must get back to my own programming LOL.

I noticed that as the game progressed and I managed to get bigger and slower drops I was trying to get the net very close to the top canvas border.

This disrupted game play in a number of ways

1. if the mouse exits the canvas the net becomes ‘stuck’ until the mouse re-enters the canvas
2. When trying to get drops in the top left corner it triggers the intro screen.
3. The net is only partially visible.

I suggest that you introduce a solid border (`borderWeoght` ~20 pixels) and reduce the game play area to inside the border. Also rather than use `mouseX` and `mouseY` to control the net position you might introduce 2 new variables `netX` and `netY` then constrain these to inside the border like this

```auto
mouseMoved(){
  // constrain the net position to inside the border
  netX = constrain(mouseX, borderWeight, width - borderWeight);
  netY = constrain(mouseY, borderWeight, height - borderWeight);
}

```

I would move the `?` button to bottom-right inside the border because it is not an area you might move the net.

Personally I think these would enhance the game and in particular the border will ‘frame’ the play area focusing the player’s attention to the game area.

Feel free to ignore these suggestions - after all it is your game not mine.

---

<div class="post-metadata">

**Author:** ![JakobVirgil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jakobvirgil/32/19932_2.png) [@JakobVirgil](https://discourse.processing.org/u/JakobVirgil)\
**Post date:** [August 10, 2024, 3:46pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/12 "2024-08-10T15:46:05Z")

</div>

Those are fantastic Ideas. Also the constrain function is something I wish I knew about before I wrote my own lim function. I am glad you are enjoying the game. Are you playing on [The Yellow Quadrangle by JakobVirgil](https://jakobvirgil.itch.io/the-yellow-quadrangle) or on the directly from p5.js?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 10, 2024, 3:50pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/13 "2024-08-10T15:50:42Z")

</div>

I have been playing in the p5.js editor though I have just visited your site and read some of the comments.

---

<div class="post-metadata">

**Author:** ![JakobVirgil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jakobvirgil/32/19932_2.png) [@JakobVirgil](https://discourse.processing.org/u/JakobVirgil)\
**Post date:** [August 10, 2024, 3:57pm UTC](https://discourse.processing.org/t/typeerror-cannot-read-properties-of-undefined-reading-5/44916/14 "2024-08-10T15:57:32Z")

</div>

Hopefully they were not too rude.  
There is a new version  
[Organic raincoat by a.king.ink -p5.js Web Editor](https://editor.p5js.org/a.king.ink/sketches/FUWhNzABq)
