Problem with makecode I have seen a few times

@top_hat_lord this isn’t a glitch, but it is an important thing to understand about how games work in arcade and how video games work in general!

games are executed one “frame” at a time. in arcade, we refer to frames as an “update”, so the “on game update” block is a block that runs code once a frame. each frame, the game engine needs to do a bunch of things including:

  1. reading controller input
  2. executing physics
  3. doing tile overlaps and collisions
  4. running player update code
  5. sorting sprites by z-index
  6. drawing the sprites to the screen
  7. starting the next frame

in that list above, each item must finish before the next step can run. for example, we can’t run physics without first checking what buttons have been pressed on the controller.

similarly, we can’t draw sprites to the screen until all of the player’s update code has finished running. that means if you put a pause inside of an “on game update” block, you will delay every step that comes after it until that pause finishes and your game will effectively freeze.

“on game update” isn’t the only block that will delay the current frame. most event blocks like “on sprite overlaps tile” or “on score reaches ___” will also delay the game if you pause inside of them. however, there are a few events where it is safe to pause. off the top of my head, they are:

  • on sprite overlaps othersprite
  • all of the controller events (on button pressed, on connected, etc.)
  • the forever loop

so does that make the pause block useless? no! you just need to be careful where you use it. if you ever need to run code after a pause in any of the other blocks, i recommend using the timers extension which will let you spawn a separate “thread” to execute the code.

for more information on what happens every frame in the game loop, read this documentation.

for more information on threads, read this blog post which i still haven’t written the part 2 of…

3 Likes