BUTTON in SmileBasic V1 is identical to that in V2.
BUTTON(mode) is a function which returns the status of the buttons. The parameter
mode is a numerical value which is rounded down; it may be omitted, the default value is 0. If a number outside the range 0 to 3 (inclusive) is used, the system gives an
Out of range (BUTTON) error; if a string is used, the system gives a
Type Mismatch (BUTTON) error; if two parameters are given, the system gives a
Syntax error (BUTTON) error. The values are updated at the beginning of every frame.
BUTTON()) returns the current state of the buttons: a bit being set indicates the button is pressed, the bit being clear indicates the button is released.
BUTTON(1) behaves like
BTRIG - for one frame after the button goes from up to down, the bit is set, then the bit is clear for all subsequent frames during the time the button is down, during the time the button is released, and it is set again only when the button goes from up to down again.
BUTTON(2) is for 'auto-repeat' buttons; for details, see
BUTTON(3) is like
BUTTON(1), except instead of indicating when the button changes from up to down, it indicates when the button is released: when it changes from down to up.
The relationship between buttons and the return value of
BUTTON is summarized in the following table:
(The usefulness of having a bit mask for SELECT is very limited, since no program will run, or continue running, when SELECT is pressed, and it will interrupt any WAIT or VSYNC executed from the interactive Run Mode. However, it is possible to see the effect of the bitmask: in interactive Run Mode, type "
PRINT BUTTON()". Press SELECT, and keep it pressed down while you tap the "Enter" key on the touchscreen. You will see the value 2048. If you check for SELECT being held down as soon as a program starts you can use it to trigger events, but you can't push it again after that or anything.)
In SmileBASIC V3, START functions like SELECT, so it is no longer useable in programs. New return values are below.
BUTTON(1) and BUTTON(2) were swapped, you now have to use BUTTON(2) to see if the button was just pressed.
Also, a terminal ID (console ID in multiplayer) can be specified to get the other console's button states.