# Error: Cannot read properties of undefined (reading 'vtable') at \<main\> (line 22)

**URL:** <https://forum.makecode.com/t/error-cannot-read-properties-of-undefined-reading-vtable-at-main-line-22/30176>\
**Category:** Help\
**Created:** [August 18, 2024, 12:22am UTC](https://forum.makecode.com/t/error-cannot-read-properties-of-undefined-reading-vtable-at-main-line-22/30176 "2024-08-18T00:22:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FlashCanBuild](https://avatars.discourse-cdn.com/v4/letter/f/97f17d/32.png) [@FlashCanBuild](https://forum.makecode.com/u/FlashCanBuild)\
**Post date:** [August 18, 2024, 12:22am UTC](https://forum.makecode.com/t/error-cannot-read-properties-of-undefined-reading-vtable-at-main-line-22/30176/1 "2024-08-18T00:22:46Z")

</div>

I found out about this error after working on an Undertale-themed battle sim: I’ve never seen this error before, no idea what a ‘vtable’ is.  
I went through the debug step into functions, and upon further inspection, it has an error with the constructor of the Bullet class (line 666) (not a hell error 👀).  
I am somewhat new to JavaScript so I could have gone about it wrong. I also tried to clone the sprite so I wouldn’t have multiple variables pointing to the same instance. (See line 668). It could also have something to do with how I did an enumerator (line 26).

> **[yellow test](https://arcade.makecode.com/S34657-37337-43442-47177)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [August 18, 2024, 12:41am UTC](https://forum.makecode.com/t/error-cannot-read-properties-of-undefined-reading-vtable-at-main-line-22/30176/2 "2024-08-18T00:41:50Z")

</div>

Great start! A few things that you’re running into.

You’re correct in that your enum is incorrectly defined. This is the `vtable` that the compiler was complaining about. It should instead look like this:

```typescript
const enum MovementType
{
    LINEAR = 1,
    HOMINGVEL = 2,
    HOMINGACCEL = 3,
    UP = 4, 
    DOWN = 5,
    RIGHT = 6,
    LEFT = 7,
    RANDOM = 8,
}

```

Also, I had to move some of your variables to the top of your code file. (Specifically, your images like `upBulletImg`, along with `bulletList`.) They need to be defined before the call to `setupPatterns()`.

As a rule, place all of your constants and global variables at the top of your code file so that they are visible to all of the code that appears below.

Take a look:

> **[yellow test](https://arcade.makecode.com/05424-82509-14998-64713)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![FlashCanBuild](https://avatars.discourse-cdn.com/v4/letter/f/97f17d/32.png) [@FlashCanBuild](https://forum.makecode.com/u/FlashCanBuild)\
**Post date:** [August 18, 2024, 1:46am UTC](https://forum.makecode.com/t/error-cannot-read-properties-of-undefined-reading-vtable-at-main-line-22/30176/3 "2024-08-18T01:46:09Z")

</div>

Thanks so much! I figured I did something wrong with the enumerator.
