Last button pressed in game is processed by editor too
-
I wrote a loop which waits for a button press before exiting my program. If I press the B button to exit my program, the editor does a backspace, modifying my source code. To reproduce, move the editor cursor to the end of a line so the backspace will actually do something. You can use the editor's undo feature to repair the damage.
loop update() ctrl = controls(0) if ctrl.b then break endif repeat
-
Looks like a bug to me. For the time being, I guess you could add a sleep call at the end to give you enough time to release the button before it goes back to the editor.
-
another solution could be waiting until the button is released before exiting out to the editor, it would stop any issues but might make it feel less responsive
-
Oh, geez, I didn't even think of that. I need to loop until the button is no longer pressed. Thank you.
-
no problem, normally if you were using a button to exit a menu it would exit as soon as you pressed it but lock that button's input until you released it, but the code editor isn't part of your program so sadly you can't change that, so i'd definitely like to see a "fix" to this, as it were
-
News and improved:
pressed = false loop update() ctrl = controls(0) if ctrl.b then pressed = true else if pressed then break endif endif repeat
-
You've stumbled upon something that I found on I think my 2nd night. If you for example increment a counter and print the result on screen when a button is pressed then you'll be expecting it to increment by 1 each press but the loop is so fast that it'll go up by quite a lot. So as you now know you keep checking until you know the button WAS pressed but isn't any more. THEN you do you action and you're golden. It might seem like a quirk but it's actually perfectly normal having to "debounce" a button.