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:
 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, causingundefinederrors.- Fix:
 

 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:
 
 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 
ifchecks inside. 
 Sprite positions with offsets
![]()
- Using decimals in tile positions is risky. 
getTileLocation()expects integers. - Fix: Round the positions:
 
![]()
 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.
 destroy_sprites() vs sprites.destroyAllSpritesOfKind

- That’s fine. But in 
ded(), you also destroy all goombas before resetting the player.
 
 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. 
 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. 
 forever loop doing nothing
![]()
- You can remove empty loops—they’re unnecessary.
 
 Possible typo
if (onerase == 0 && onreset == 0 && oncurrentblock == 0)
- Later, you use 
onerasebut earlier you wroteonerasewithe? Make sure variable names are consistent. 
 Summary of main actionable fixes
- Change 
<= Xpos.length→< Xpos.length. - Round tile positions when using 
tilemapLocation(). - Combine redundant 
forever()loops to improve performance. - Ensure all global vars are initialized before use.
 - Review 
.insertAt(0)vs.push()logic for block placement order. - Avoid empty or overlapping 
forever()loops with sound/music.