Game freezing on PyBadge

My Super Mario Maker like game is freezing on my PyBadge and I don’t know why. Here’s the link if you want to help: https://arcade.makecode.com/S56169-18796-80738-18523

1 Like

Alright, I took a careful look at this code. From a MakeCode Arcade / TypeScript perspective, here are some key things you or someone else might want to fix or watch out for:


:one: Array out-of-bounds in make_level()

for (let index = 0; index <= Xpos.length; index++) {
    tiles.setTileAt(tiles.getTileLocation(Xpos[index], Ypos[index]), blocks[Type[index]])
}
  • index <= Xpos.length → This will go one past the last index, causing undefined errors.
  • Fix:

image


:two: Global variables without initialization

You have a ton of global variables like Xpos, Ypos, Type, blocks, Mario, making, etc.

  • Some are initialized at the bottom of the script, but if functions run before initialization, you’ll get errors.
  • Good practice: Initialize all of the variabes at the top with defaults:

:three: Repeated forever loops doing similar things

You have dozens of forever() loops, many of which check controller.A.isPressed() or making and then perform actions.

  • Problem: This can lag the game. MakeCode executes each forever() independently, so heavy logic in multiple loops can slow the engine.
  • Better: Combine related logic into fewer loops with if checks inside.

:four: Sprite positions with offsets

image

  • Using decimals in tile positions is risky. getTileLocation() expects integers.
  • Fix: Round the positions:

image


:five: Xpos.insertAt(0, …) logic

You’re inserting at 0 every time, meaning the arrays are in reverse order. If you care about placement order, consider using .push() instead.


:six: destroy_sprites() vs sprites.destroyAllSpritesOfKind

image

  • That’s fine. But in ded(), you also destroy all goombas before resetting the player. :white_check_mark:

:seven: Music/Sound Overlaps

  • You have multiple music tracks playing in parallel in different forever() loops. This can conflict.
  • Recommendation: Only play music when needed or use music.stopAllSounds() before playing a new track.

:eight: onreset, oncurrentblock, onerase logic

  • These flags control if you can reset, erase, or place blocks.
  • Seems okay, but check that pauseUntil() calls don’t block other logic you want running. Blocking in one loop can freeze animations.

:nine: forever loop doing nothing

image

  • You can remove empty loops—they’re unnecessary.

:ten: Possible typo

if (onerase == 0 && onreset == 0 && oncurrentblock == 0)
  • Later, you use onerase but earlier you wrote onerase with e? Make sure variable names are consistent.

:white_check_mark: Summary of main actionable fixes

  1. Change <= Xpos.length< Xpos.length.
  2. Round tile positions when using tilemapLocation().
  3. Combine redundant forever() loops to improve performance.
  4. Ensure all global vars are initialized before use.
  5. Review .insertAt(0) vs .push() logic for block placement order.
  6. Avoid empty or overlapping forever() loops with sound/music.