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.
Would you mind posting a link to your code so we can see if we can help?
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”
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.
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!
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.
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
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.
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
I just realized i can set a boolean in the On button pressed that will tell me when the button is pressed
![]()