hello, so while developing makecode games I have had to dela with bugs before. simple things that need fixing, sometimes hard to see, sometimes just random. But one thing has appeared to again without reason, and I must talk about it. simply this is a bug where the entire game pauses when I use the pause block in blocks. I don’t know why this happens, but I don’t think the timer extension works when a file has this type of glitch. I don’t know if it’s some problem with a certain extension, but I don’t think it should affect a block that’s in the main thing of makecode arcade. has anyone have any of you seen this glitch before? do any of you have a fix for this? if so, please mention it. as I don’t know what’s happening. here’s the game in question this is happening in, and please do mention if this is or isn’t happening on your end, because I honestly don’t know if it is or isn’t going to.
@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:
- reading controller input
- executing physics
- doing tile overlaps and collisions
- running player update code
- sorting sprites by z-index
- drawing the sprites to the screen
- 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…
Thanks Richard, that helps a lot!
because you have the “sprite utils” extension (https://github.com/jwunderl/arcade-sprite-util) put the code in the '“on game update” into a “run code [before] the game [updates the controller],” and change [updates the controller] to [updates the screen].