# Run a function before pausing

**URL:** https://forum.makecode.com/t/run-a-function-before-pausing/6514
**Category:** Help
**Created:** [March 3, 2021, 7:50pm UTC](https://forum.makecode.com/t/run-a-function-before-pausing/6514 "2021-03-03T19:50:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [March 3, 2021, 7:50pm UTC](https://forum.makecode.com/t/run-a-function-before-pausing/6514/1 "2021-03-03T19:50:26Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/f1aaa092349a0ad46d6153a2ecf02566345b63ec.png)  
Can I schedule a callback right before the menu opens and after it closes? When it pauses, it breaks a part of my game, but I _think_ I know how to fix it.

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [March 3, 2021, 7:51pm UTC](https://forum.makecode.com/t/run-a-function-before-pausing/6514/2 "2021-03-03T19:51:09Z")

</div>

No way to do this right now, but maybe it’s something we should do… If you add a button handler for the menu it will disable the built-in one.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [March 3, 2021, 8:06pm UTC](https://forum.makecode.com/t/run-a-function-before-pausing/6514/3 "2021-03-03T20:06:54Z")

</div>

Maybe at least expose it in JS so someone could write an extension to do that?

---

<div class="post-metadata">

### Author: ![kwx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kwx/32/1545_2.png) [@kwx](https://forum.makecode.com/u/kwx)
#### Post date: [March 3, 2021, 8:14pm UTC](https://forum.makecode.com/t/run-a-function-before-pausing/6514/4 "2021-03-03T20:14:38Z")

</div>

> [@richard](#):
>
> If you add a button handler for the menu it will disable the built-in one.

How about something like this?

```
controller.menu.onEvent(ControllerButtonEvent.Pressed, function() {
    // do stuff before system menu
    scene.systemMenu.showSystemMenu()
    // do stuff after system menu
})

```

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [March 3, 2021, 8:14pm UTC](https://forum.makecode.com/t/run-a-function-before-pausing/6514/5 "2021-03-03T20:14:54Z")

</div>

yep, that would work!

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [March 3, 2021, 8:24pm UTC](https://forum.makecode.com/t/run-a-function-before-pausing/6514/6 "2021-03-03T20:24:18Z")

</div>

Yes! It works! Thanks 🙏

Also, if anyone else needs to do the same like me and have JS commands in blocks, this is what I do:  
**THIS ONLY WORKS IF YOU USE GITHUB INTERGRATION**

1. Commit to GitHub.
2. Go to JS.
3. Type the command you need.
4. Go back to blocks.
5. If the layout isn’t messed up, nice! If it is, keep going.
6. Select the JS block and press ctrl + c
7. Revert all changes.
8. Press ctrl + v.
9. The block should be somewhere!
