# createVector returning undefined

**URL:** <https://discourse.processing.org/t/createvector-returning-undefined/1922>\
**Category:** p5.js\
**Created:** [July 19, 2018, 11:23pm UTC](https://discourse.processing.org/t/createvector-returning-undefined/1922 "2018-07-19T23:23:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liam\_McLeod44](https://avatars.discourse-cdn.com/v4/letter/l/0ea827/32.png) [@Liam\_McLeod44](https://discourse.processing.org/u/Liam_McLeod44)\
**Post date:** [July 19, 2018, 11:23pm UTC](https://discourse.processing.org/t/createvector-returning-undefined/1922/1 "2018-07-19T23:23:59Z")

</div>

Hi, I was recently going through one of Daniel Shiffman’s old smart rockets tutorial. My code is very similar to his only with updated syntax. I ran into an error early on which was **Uncaught TypeError: Cannot read property ‘add’ of undefined**. This happens on line 13. Here is my code.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/128d5d5d9fb26ab4ce670a2f5f6d37311f073cd3.png)

For some reason all of the vectors created in the constructor become undefined when I reference them elsewhere. I have printed them all out to confirm this. I am using the latest version of Atom on Windows 10 and have tested it with both Google Chrome and Firefox. Hope you can help!

---

<div class="post-metadata">

**Author:** ![Liam\_McLeod44](https://avatars.discourse-cdn.com/v4/letter/l/0ea827/32.png) [@Liam\_McLeod44](https://discourse.processing.org/u/Liam_McLeod44)\
**Post date:** [July 19, 2018, 11:24pm UTC](https://discourse.processing.org/t/createvector-returning-undefined/1922/2 "2018-07-19T23:24:51Z")

</div>

Here is the sketch part of the code:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/c31b760dd87163bde0ee26b1d61224a301898795.png)

---

<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:** [July 19, 2018, 11:40pm UTC](https://discourse.processing.org/t/createvector-returning-undefined/1922/3 "2018-07-19T23:40:04Z")

</div>

Please avoid posting code as a picture, b/c they can’t be copied & pasted, and can even be harder to read! 😧

Since it’s JS, you should post it as a runnable app on some JS hosting site: 🤩

> **[My Sketch - Guest User - OpenProcessing](https://openprocessing.org/sketch/create)**

[![](https://img.youtube.com/vi/vNjobQiQZns/hqdefault.jpg "9.18: p5.js with OpenProcessing and Processing IDE - p5.js Tutorial") ](https://www.youtube.com/watch?v=vNjobQiQZns)

Back to your problem, w/o seeing your “.html” file as well, I can’t pinpoint exactly what is wrong there! 😶

As an example, the order your “.js” script files are loaded & run might be wrong. 🤔

---

<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:** [July 19, 2018, 11:46pm UTC](https://discourse.processing.org/t/createvector-returning-undefined/1922/4 "2018-07-19T23:46:12Z")

</div>

For now, you might be interested in seeing a sketch w/ multiple “.js” files loaded from its “index.html” file: 🤠

> **[Toxic VerletParticle2D](https://Bl.ocks.org/GoSubRoutine/f4e383cfc4de8b063df3ee1c3fc66419)**
>
> GoSubRoutine’s Block f4e383cfc4de8b063df3ee1c3fc66419

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [July 20, 2018, 12:03am UTC](https://discourse.processing.org/t/createvector-returning-undefined/1922/5 "2018-07-20T00:03:37Z")

</div>

Also, there is a p5.js mode that can be downloaded in the Processing IDE as well.

---

<div class="post-metadata">

**Author:** ![Liam\_McLeod44](https://avatars.discourse-cdn.com/v4/letter/l/0ea827/32.png) [@Liam\_McLeod44](https://discourse.processing.org/u/Liam_McLeod44)\
**Post date:** [July 20, 2018, 12:48am UTC](https://discourse.processing.org/t/createvector-returning-undefined/1922/6 "2018-07-20T00:48:51Z")

</div>

HTML part:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/ecb7d1a3bfbfb8701bed38009f9173b43f80a766.png)

---

<div class="post-metadata">

**Author:** ![Liam\_McLeod44](https://avatars.discourse-cdn.com/v4/letter/l/0ea827/32.png) [@Liam\_McLeod44](https://discourse.processing.org/u/Liam_McLeod44)\
**Post date:** [July 20, 2018, 12:55am UTC](https://discourse.processing.org/t/createvector-returning-undefined/1922/7 "2018-07-20T00:55:09Z")

</div>

Thanks for the feedback. I added a photo of the html file as well. It turns out the issue is fixed if I switch back to ES5 syntax in Atom and It also works with ES5 syntax in the processing IDE. I don’t understand why it does not work with ES6 syntax. I tried Shiffman’s evolutionary steering with ES6 syntax in Atom and it works fine using the same createVector and add properties.
