Need debugging help

I created a game last summer and it was going well. I had the game running in the browser and on PyBadge and PyGamer hardware. I took some time off between 6/26 and 9/09 and when I added some something stopped working with the detection of sprite overlaps. I’d like to try debugging it but I can’t seem to figure out how to set a breakpoint. Are their any good tutorials on how to debug MakeCode Arcade games? I’ve been doing the coding in Blocks so I can show my kids how it works but I also have a general understanding of JavaScript and Python (my primary programming languages are C/C++ and Perl).

The really annoying part is that a tried to build a basic stripped down version of my game to test the problem, and the stripped down version works.

I have a player and I have an enemy. The player can shoot a projectile to kill the enemy. The player can also press the other button to draw a “sword” to kill the enemy. In both games the overlap of sprite of type Projectile and Enemy works as expected. In the stripped down version the Overlap of sprite of type “sword” and othersprite of type Enemy works as expected. It does not work in my other game.

For now I would kind of like to keep my “broken” version of the game private until I feel like it’s Done enough to share. That’s why I was trying to build a stripped down version that reproduced the problem so I could share that. Unfortunately I failed to fail. :slight_smile:

2 Likes

Here’s how to set a break point in blocks:

And in text mode: (I use JS for this example but it’s the same in Python)

1 Like

@UnsignedArduino’s gifs shows how to use the debugger which is super helpful. Without looking at the code it’s hard to say exactly what is going on, but a few possibilities;

  • is the larger game possibly setting a sprite involved in the overlap to be a ghost?
  • create and save a share link before trying this as switching to javascript might mess up any formatting / ordering you have in your blocks – If you click ‘JavaScript’ at the top to go to the JavaScript view, and then ctrl+f searching for ‘SpriteKindLegacy’, does anything show up? If not, does searching through all references for SpriteKind show anything surprising in the blocks? This wouldn’t make a ton of sense with the time period you mentioned, but it is something we’ve run into in the past. In early, pre-‘official release’ incarnations of arcade we had a different representation for SpriteKinds, and mixing them up in the same program can result in blocks that look valid that have different underlying representations.

Similar to above, one approach might be to grab this block from the sprites category:
image
and drag it onto all references to spritekinds, to make sure they’ll all using the same representations. If it works then everything will be up to date / any future blocks you add should work as is.

(If that doesn’t work, I can also send you a message with my admin powers and you can send a share link just to me so I can see what’s up.)

1 Like

Wow thanks for the quick responses. I didn’t see any SpriteKindLegacy when I was looking at the python code earlier and the types seemed to look right (SpriteKind.sword) between the sprite being created and the overlap function. The Enemy sprite is definitely not a ghost because I can kill it with projectiles.

I’ll try the mySprite kind block to see if that works and I’ll give the breakpoints a try too.

1 Like

Luckily I save PNG exports of various versions of my game with datestamps and feature adds in the file names because I can now go back and try importing older versions in a different browser or incognito window. Turns out a quick test of the older version that used to work back in June last year, doesn’t work anymore. I tried setting a breakpoint on the first block inside “if sprite of kind sword overlaps with othersprite of kind enemy” and it never gets called. Why can’t I set the breakpoint on the actual “IF” block?

Later I’m going to try loading older versions to see how far back I need to go to get working code. I’m wondering if one of the extensions I added in broke something. Off the top of my head I know I added the arcade-sprite-data extension so I could have health points and other attributes on my sprites. I also have button-combos and color-coded-tilemap added. Just noticed the multiple tilemaps extension. Might have to check that out since I am swapping out the color-coded-tilemaps in my game.

More info to come when I get more time to test.

There should be a circle for it:

image

Sorry I mentally converted to “IF” when looking at the “On sprite of kind … overlaps otherSprite of kind …” I suppose I should have called it an event handler. There isn’t a circle for the On block so I have to put one on the first block inside that handler. Ultimately it might work out to be the same effect.

I pulled some Python snippets from my code that show the SpriteKind of sword being created and that when the B button is pressed (but not also A for a combo) that the sword Sprite is created and then the two handlers for when the sword overlaps with an Enemy or a Prey. Those two on_on_overlap methods never trigger. However I have other on_on_overlap methods that look for SpriteKind.projectile overlapping with Enemy or Prey that do work.

class SpriteKind:
    sword = SpriteKind.create()
    weak_to_sword = SpriteKind.create()
    weak_to_spell = SpriteKind.create()
    Loot = SpriteKind.create()
    Info = SpriteKind.create()
    prey = SpriteKind.create()

def on_b_pressed():
    global weapon
    if not (in_inventory):
        if not (controller.A.is_pressed()):
            weapon = sprites.create(img("""
                    . . . 1 . . . . . . 
                                    . . 1 . . . . . . . 
                                    e e 1 1 1 1 1 1 1 1 
                                    . . 1 . . . . . . . 
                                    . . . 1 . . . . . .
                """),
                SpriteKind.sword)
            weapon.set_position(Hero.x + 8, Hero.y + 4)
controller.B.on_event(ControllerButtonEvent.PRESSED, on_b_pressed)

def on_on_overlap(sprite, otherSprite):
    REDACTED
sprites.on_overlap(SpriteKind.sword, SpriteKind.enemy, on_on_overlap)

def on_on_overlap2(sprite, otherSprite):
    REDACTED
sprites.on_overlap(SpriteKind.sword, SpriteKind.prey, on_on_overlap2)
1 Like

Ah, if you put a breakpoint directly on that event handler, then it would break when the event handler is defined, not when it is called. So you just need to place one on the first block in there.

The version I saved as a PNG on 6/26 which works on the PyBadge hardware back when I downloaded it, no longer works on the simulator.

I pulled the UF2 file off my PyBadge and uploaded it into an incognito browser and it does not work in the simulator.

I ran strings on the UF2 file hoping to find some version strings that would help and some potentially useful values seem to be
PyBadge
v3.10.0
arcade.makecode.com
arcade.uf2
PYBADGEBOOT
Adafruit Industries
UF2 UF2
PYBADGEBOOTFAT16
<!doctype html>

INFO_UF2TXT
INDEX HTM
CURRENT UF2
UF2 Bootloader v3.10.0 SFHWRO
Model: PyBadge
Board-ID: SAMD51J19A-PyBadge-M4
yz" >
v1.1 [Arduino:XYZ] May 17 2020 17:56:09
UURL":“https://arcade.makecode.com/",“eVER”:“0.15.18”,“pxtTarget”:"arcade”}]

I tried to use the “mySprite kind” block but the code won’t run because the weapon/sword sprite doesn’t exist before the user pushes the B button.

Oh! I put a screenshot of the wrong block there, sorry for that! I should have screenshotted

image

but I must have gotten distracted…

Without seeing the file I’m not sure what else it could be right away, but it’s worth noting older versions of the site are still accessible; e.g. https://arcade.makecode.com/v0.15.18 is the version that is listed as the one you used to make that file. Might be helpful to try loading in there to verify it worked then. Each change in this file https://github.com/microsoft/pxt-arcade/commits/master/docs/index-ref.json is a release that we pushed out / that changed the normal website, so you can at least see when it broke from that.

1 Like

OMG giving me the link to the old versions (something I meant to ask about) Helped so much. I tested the same UF2 file all the way up to v0.18.5 and it works. It breaks in v0.18.6 so after some dinner I’ll try to figure out what changed.

1 Like

Hm, the only thing that pops out right away between those two versions would be https://github.com/Microsoft/pxt-common-packages/compare/v6.17.6...v8.0.4#diff-d04b60cfee5d62de0867936605a7f215168059b912a33a2922aeb797f700c1c1R338-R342 in libs/game/physics.ts – which effectively was a fix that said “if one of the two sprites changed in such a way that it can no longer collide between when the overlap was detected and when the overlap handler is run, do not run the handler” – this would be the case if a sprite was destroyed, became a ghost, or something of the sort while physics was running, e.g. due to a tile collision – https://github.com/microsoft/pxt-common-packages/blob/94c80ef2bcdee6fcd74b49c9383fe583a59b27f6/libs/game/physics.ts#L31

1 Like

That is a good clue. Let me check how I’m handling the sword position updates when the player is moving.

Ok that was the problem. If the player was holding B (sword out) while moving, every game update I was destroying the sword and respawning it at the correct place relative to their position. In the past when I did not destroy it, there would be a trail of swords all over the ground. I also had to destroy it just in case they changed their horizontal direction so I could redraw the sword on the correct side.

I fixed it by just swapping the sprite image to left of right facing as necessary and then updating the position relative to the player without destroying the sprite.

Thank you SOOOOO much for staying on top of this issue and being patient with my perfectionism making me not want to share the game yet.

2 Likes