How does the menu button pause everything?

I need to know how the menu button pauses my whole game. I want to create my own pause screen but whenever I do that background sprites still move (unlike the built in menu screen).

4 Likes

I’m pretty sure you want to put EVERY single piece of code into an if block that checks if the main menu is open, if it’s not, run the code.

1 Like

I think the menu screen is in its own function. If you put a very long loop inside a function, you’ll notice that the whole game freezes until it is done. The only problem is that the whole game freezes, meaning the screen doesn’t update, so making a functioning pause screen wouldn’t really work, at least not if you were only using blocks…
Of course, if you aren’t using block code, you should take a look in the explorer in Game, Systemmenu.ts and scroll around, you might find out how to do what the system menu does!

1 Like

Ok, I was kinda curious myself so I did some digging. Turns out that Makecode uses “scenes” to keep track of everything, and there is actually built in functionality to “push” the current scene out somewhere else and then create a new scene. You can then “pop” the old scene back, deleting the second scene you made and replacing it with the old one! These functions haven’t been made into blocks, but if you want to use them in written code they are game.pushScene() and game.popScene()

(The code for these functions in the explorer is in game → game.ts, around line 150)

It would be really annoying to turn this into an extension because, when the current scene is “pushed”, all the “on button pressed” definitions go away with it, so you need to define them again after you push the scene. Block code doesn’t really have a way to re-define those functions, so anyone making an extension would need add that functionality too.

If someone wants to turn this into an extension, be my guest, but it won’t be that simple!

Here’s a small demo I made in JavaScript if anyone wants to play around with it:

(Hopefully this will get approved after the first message I wrote)

2 Likes

hey me too because ngl it kind of looks ungly

1 Like

And I kinda want to get into extension creating (if you know anything about that) how easy is it and like what is the process?

1 Like

Okay thanks this is very helpful!

1 Like

I know a bit about extensions. Basically, you make some useful functions, and then you use a bunch of syntax stuff to tell Makecode how to turn those functions into blocks. I started by opening extensions and looking inside, copying them, and changing around stuff to see how it effected the blocks!

1 Like