# "is button pressed" only returning false, but why

**URL:** <https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618>\
**Category:** Help\
**Created:** [July 8, 2024, 6:10pm UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618 "2024-07-08T18:10:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ploop](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@ploop](https://forum.makecode.com/u/ploop)\
**Post date:** [July 8, 2024, 6:10pm UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/1 "2024-07-08T18:10:51Z")

</div>

Hello! I’m hoping to used the block “is _insert button_ button pressed” block, as i’ll have lots of functionalities for one button pending on where you are in the game- alot easier than setting a bunch of conditionals in the “on button pressed” handler. BUT no matter what button and when i press the button- it always returns false. I logged it at the highest level to make sure nothing was impeding/no random conditions in the way and haven’t had any luck. Is this a known issue or am i just not understanding how that boolean works.

---

<div class="post-metadata">

**Author:** ![KIKIvsIT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kikivsit/32/10492_2.png) [@KIKIvsIT](https://forum.makecode.com/u/KIKIvsIT)\
**Post date:** [July 8, 2024, 6:11pm UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/2 "2024-07-08T18:11:13Z")

</div>

Would you mind posting a link to your code so we can see if we can help?

---

<div class="post-metadata">

**Author:** ![ploop](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@ploop](https://forum.makecode.com/u/ploop)\
**Post date:** [July 8, 2024, 8:14pm UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/3 "2024-07-08T20:14:55Z")

</div>

sure thing, thank you!!!  
its a little broken right now on the actual button presses but I left comments starting from the top and scrolling down- showing where i would like to use “is button pressed”- the mess that will be a bunch of conditionals on “on button pressed” and the behavior of “is button pressed”

[https://arcade.makecode.com/S74671-62687-79004-37618](https://arcade.makecode.com/S74671-62687-79004-37618)

---

<div class="post-metadata">

**Author:** ![KIKIvsIT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kikivsit/32/10492_2.png) [@KIKIvsIT](https://forum.makecode.com/u/KIKIvsIT)\
**Post date:** [July 8, 2024, 8:20pm UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/4 "2024-07-08T20:20:48Z")

</div>

Alrighty. It looks like the current version doesn’t use the “is button pressed” but uses “on button pressed” with conditionals, and that’s what you would like to switch? If you can post a version where you try it and it’s not working, I may be able to tell you why.

Keep in mind that it only checks if that button is pressed at the very moment (not whether it HAS been pressed) so you often need to either pause and wait for a button press or use a loop to check for one.

---

<div class="post-metadata">

**Author:** ![ploop](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@ploop](https://forum.makecode.com/u/ploop)\
**Post date:** [July 8, 2024, 10:55pm UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/5 "2024-07-08T22:55:48Z")

</div>

Okay sweet. So putting a console log in an if statement “if is button pressed” wouldn’t produce a log? I did just now throw a test into the “on start” it would throw a log and change scene as well as set a sprite(but does not) Hope that’ll help!

---

<div class="post-metadata">

**Author:** ![KIKIvsIT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kikivsit/32/10492_2.png) [@KIKIvsIT](https://forum.makecode.com/u/KIKIvsIT)\
**Post date:** [July 8, 2024, 11:00pm UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/6 "2024-07-08T23:00:01Z")

</div>

It would only work if the button was held in the fraction of a second that it was checking. To use it effectively, it needs to be in some kind of game loop.

---

<div class="post-metadata">

**Author:** ![ploop](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@ploop](https://forum.makecode.com/u/ploop)\
**Post date:** [July 9, 2024, 12:37am UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/7 "2024-07-09T00:37:59Z")

</div>

what would be a game loop? is there a way to use the event handler within a self made function if that was the option to use? i imagine many games on makecode have had multiple functions for a button pending on game state so i feel like missing something on how to make that happen haha

---

<div class="post-metadata">

**Author:** ![KIKIvsIT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kikivsit/32/10492_2.png) [@KIKIvsIT](https://forum.makecode.com/u/KIKIvsIT)\
**Post date:** [July 9, 2024, 12:40am UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/8 "2024-07-09T00:40:20Z")

</div>

You could try using a flag. Have the “on button pressed” event check the flag. If it’s set to 1: \_\_\_ happens, 2: \_\_\_\_ happens, 3: \_\_\_\_ happens, etc.? Then all you need to do is change the flag as the character goes makes its way through the game.

---

<div class="post-metadata">

**Author:** ![ploop](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@ploop](https://forum.makecode.com/u/ploop)\
**Post date:** [July 9, 2024, 3:04am UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/9 "2024-07-09T03:04:39Z")

</div>

it’ll be one long if else statement with loads of conditions/edgecases but it is possible though not ideal and easily buggy- i was hoping there would be a way to call button events in the current function called but alas a mega conditional, here we come! haha

---

<div class="post-metadata">

**Author:** ![ploop](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@ploop](https://forum.makecode.com/u/ploop)\
**Post date:** [July 9, 2024, 5:22pm UTC](https://forum.makecode.com/t/is-button-pressed-only-returning-false-but-why/29618/10 "2024-07-09T17:22:49Z")

</div>

I just realized i can set a boolean in the On button pressed that will tell me when the button is pressed 🙃 😅
