LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Pressing A during an INPUT

Root / Programming Questions / [.]

WaulyCreated:
Hi guys! I'm new to this website but not too new to smileboom. I had petit computer and now smilebasic and I have a lot of fun toying and learning. Anyway, I have this problem where when I INPUT a name and press A to enter it (while the game is running of course) it keeps A pressed for my actual "if button(2) and #a".

Try putting a VSYNC after the INPUT. That will insert one frame between the input and the next check, which gives tells the 3DS to check for a new trigger rather than use the one from the current frame. If that's not enough, you can do a bit more, like vsync 5. Edit: nevermind, one should be enough.

I've tried that before. It doesn't work :/ Edit: should I mention my buttons are in a while loop? And the A button BREAKs the loop

You know what, a vsync 60 does the job. I'm just surprised BUTTON(2) would do this to me D: Edit: Actually, this is strange. I tested the lowest vsync I could do, holding down A with the input and I got VSYNC 29, but, when I move the "IF BUTTON(2) and #A..." to the top line of my while loop, VSYNC 28 works. So the processing is taking some time someplaces I guess? I did a test
ACLS
INPUT "Name";N$
VSYNC X
WHILE WLOOP==0
IF BUTTON(2) AND #A THEN BREAK
IF A==0 THEN ?"While" A=A+1
WEND
?"Break"
Tested by holding A after inputting a name. If "While" shows up, it worked. I noticed it was inconsistent and the time for "While" to show up was also Edit2: I edited the program to this
ACLS
INPUT "Name";N$
B=MAINCNT
VSYNC X
WHILE WLOOP==0
IF BUTTON(2) AND #A THEN BREAK
C=MAINCNT-B
IF A==0 THEN ?C A=A+1
WEND
?"Break"
Instead of printing "While", now it prints how many frames it took to get to the while loop if the amount of VSYNC allows it VSYNC 400 is around the sweet spot. something like 380 works a fraction of the time the frame count is pretty much always different It's just a mess

Sounds like one of those lovely SmileBASIC bugs.

BUTTON(2) is just awful. I just use BUTTON() and some extra code like this:
WHILE 1
 'main loop
 OB=B
 B=BUTTON()
 IF B && !OB THEN
  'button press detected
 ENDIF
WEND

BUTTON(2) is just awful. I just use BUTTON() and some extra code like this: WHILE 1 'main loop OB=B B=BUTTON() IF B && !OB THEN 'button press detected ENDIF WEND
That worked great! But did I get this right? I said "IF B AND 16 && !OB THEN blah blah"

For a more complete solution:
OB=B
B=BUTTON()
BUTTON2=B AND NOT OB
Then use BUTTON2 like you would BUTTON(2) (the difference being that it actually works) Example: detecting an A press:
IF BUTTON2 AND #A THEN ...

Now I could be wrong, but I'm fairly certain the VSYNC needs to be INSIDE of the loop, in order to work optimally. I've done many loops similar to the code you gave above, with the vsync inside, and I haven't had an issue like that.
@LOOP
VSYNC 1
IF(BUTTON(2) == 16) THEN BEEP
GOTO @LOOP
Again, I could be wrong. I apologize if I'm wrong. I'm not an expert. :p

okay okay here we go guys
WHILE !(BUTTON() AND #A):VSYNC:WEND

REPEAT
VSYNC
UNTIL BUTTON AND #A
this is getting off topic...