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

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 :eyes:).
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).

Thanks for any help!

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:

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:

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

1 Like