Microsoft MakeCode

Sprite grid extension error

I trying to use @darzu’s amazing Sprite Grid extension in a “merge type” game. Before, moving the cursor worked perfectly fine. When I failed to make the cursor selection code, I removed it but now even moving the cursor doesn’t work. I get an error saying Program Error: Cannot read property of 'vtable' of null. I am very confused because I looked thought grid.ts but searching for vtable returns nothing. There is literally no possible way to access an undefined variable in my code to my knowledge.
Here is the link:

Thank you for your time and help.

Hey this looks great!

Sorry for the really confusing error message. I’ll see if I can make that better.

Currently there’s a limitation in Sprite Grid that only one sprite can be at a particular location at a time. So when you have this code:

You were placing both cursors at (5,10) so the second cursor was taking the place of the first one and kicking it off the grid. Then when you try to do a grid move on the first one it was erroring (in a very inconvenient way) because the first one isn’t on the grid anymore.

Sprite Grid needs to be updated to support multiple sprites per cell. How I worked around this was by not having the cursors be part of the grid… which is annoying.

Oh also you don’t need to call “snap” before “place”. I noticed you did that a few times. “grid place” should add items to the grid correctly. “snap” just internally calls “grid place” at the current location of the sprite.

Thanks for trying it out!

1 Like

Ah, that makes more sense.
Thank you so much!
I’ll probably just move the selected cursor to 0, 0 and teleport it over to the cursor’s last position probably ghost it or swomething like that, as you did.

Oh also you don’t need to call “snap” before “place”. I noticed you did that a few times. “grid place” should add items to the grid correctly. “snap” just internally calls “grid place” at the current location of the sprite.

I honestly thought that would initialise something and if I didn’t do it, it would probably throw some not defined error or something like that.

Thank you so much for making this extension. I wish I had when I made Crossy Roads 2 :wink:

1 Like

Thanks for using it and the feedback! I’ll try and get some improvements out soon.

Let me know if you think of new blocks or modes that would be helpful.

Alright, I upgrade Sprite Grid to support multiple sprites per location: https://github.com/darzu/arcade-grid/commit/924478e098dfcb3eca00b2e89075ad32a58b86e9

It does seem to fix the issue you had in Merge Garden: https://makecode.com/_UD1FmyWdc4Lq

Also GemCrush w/ the new version: https://makecode.com/_hgWCzoRgWLgs

It’s possible that in long running games there might be issues with the multiple sprites per location. To fix that I’ll just need to run some periodic cleanup code. So if you see things slowing down or get other issues, let me know!

1 Like

Thank you so much!
I really love this extension!

1 Like