? Prevent Repeating Buttons (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
💀

Prevent Repeating Buttons

  • #1 ✎ 4 Tovical 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... Posted Edited by Tovical
  • #2 ✎ 167 PixelStudio 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 Posted
  • #3 ✎ 4 Tovical 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 Posted
  • #4 ✎ 308 joelable First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself Video Games I like to play video games! Hobbies 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. Posted
  • #5 ✎ 4 Tovical 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? Posted
  • #6 ✎ 308 joelable First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself Video Games I like to play video games! Hobbies 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. Posted
  • #7 ✎ 167 PixelStudio
    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
    Posted
  • #8 ✎ 41 DasEtwas 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() [email protected] The thing you want then is BT. Posted