How do you use the buttons
Root / Programming Questions / [.]
ElzoBroCreated:
Make a variable or just use BUTTON(). As in:
IF BUTTON()=={blah blah} THEN {blah}
The first blah is what you want the button to be. It's quite hard to remember them all:
1- up
2- down
4- left
8- right
16- a button
32- b button
64- x button
128- y button
256- l trigger
512- r trigger
For example, if I want the program to wait until the A button is pressed, then I would put something like:
@LOOP
IF BUTTON()==16 THEN GOTO @BLAH
GOTO @LOOP
If you need any more scenarios or examples you can always ask. People here are glad to help!
Wait so what if i wanted a certain beep to come from pressing the buttonYou would put a beep command in @BLAH
@LOOP IF BUTTON()==16 THEN GOTO @BLAH 'this part GOTO @LOOP
You don't need to remember the button codes in SmileBASIC, there are pre-defined constants for that:
IF BUTTON() AND #A THEN BEEP
I would recommend using AND instead of == because it allows for pressing other buttons with it. So for example, if you are holding L and press A, it wouldn't detect A being pressed if you used ==, but it would if you used AND.
I'm not sure if you understood me; in my example, you wouldn't care about the other button (L). All you want to know is if the user pressed A, but pressing another button while pressing A will prevent the following from working:
IF BUTTON() == #A THEN BEEP
With this you can ONLY be pressing A and nothing else or else it won't BEEP; Holding L while pressing A won't trigger this.
By doing this:
IF BUTTON() AND #A THEN BEEP
You can be pressing all the buttons you want and it would ignore them, only caring about if you pressed A; you could be holding UP, DOWN, L, R, etc. and press A and it will still BEEP.