LoginLogin

Prevent Repeating Buttons

Root / Programming Questions / [.]

TovicalCreated:
Sorry, terrible noob question, but how do I make button presses register only once? I found BREPEAT, but I must be badly misunderstanding how it works.
BREPEAT 4
WHILE 1
IF BUTTON(3) AND #A THEN PRINT "A"
WEND
Then, when I run it and press A the screen fills with A all the way down the screen. Edit: Okay, I just realized how I'm using BREPEAT is just turning the feature off. Still, my questions about how to make a button press only register once remains, because I don't feel like setting time constraints on a button press is the right way to do it...

I think i understand what you mean...try this @test Cls B=button(2) if b and 16 then print "A" Vsync 1 Goto @test Also if this isn't what your looking for then just make another loop thats the same but change the variable of button. So instead of b make it something else like c

Thank you! That did what I needed; now I just need to compare the two sets of code to see why yours worked and mine didn't, so I can understand the language better xD

The button() function functions differently for every number inside of the parens. For 0, it's just if it's pressed. For 2, it's just the instant it's pressed, so it's only inputted once, until you let go of a button. The others are different though, but these are usually used the most.

Some testing solved it - my code would have worked, too, if I had used VSYNC. Perhaps someone can help me understand what it is that VSYNC does that turns the output from A A A ... etc. to just a single A?

VSYNC pauses the program for a set amount of frames. If a number after VSYNC is omitted it will just wait 1 frame, what most programs usually wait in a loop. Omitting a VSYNC in a loop like yours would turn the one button input into a lot, because the program is running extremely fast. Putting the VSYNC allows the program to pause an unnoticeable amount, yet let things like button inputs only happen once.

Thank you! That did what I needed; now I just need to compare the two sets of code to see why yours worked and mine didn't, so I can understand the language better xD
Yeah, anytime

if you have a long code inside of your main loop, button(2) may miss sometimes, so here is the oldschool variant: @LOOP B=BUTTON() IF B!=BLAST THEN BT=B BLAST=BUTTON() GOTO@LOOP The thing you want then is BT.