# BazzBasic Reserved Words

Complete list of all reserved keywords. All are case-insensitive.  
Variables must end with `$`, constants with `#` — they cannot share names with keywords.

---

## Control Flow
| Keyword | Description |
|---------|-------------|
| `DEF` | Begin function definition (`DEF FN name$(...)`) |
| `DIM` | Declare array (re-DIM of an existing global array keeps its contents) |
| `ELSE` | Alternative branch in IF block |
| `ELSEIF` | Chained condition in IF block |
| `END` | Terminate program; also `END IF`, `END DEF` |
| `ENDIF` | Close IF block (alias for `END IF`) |
| `EXIT` | Leave a loop early: `EXIT WHILE`, `EXIT FOR` |
| `FN` | Call user-defined function (`FN name$(...)`) |
| `FOR` | Begin counted loop |
| `GOSUB` | Call subroutine at label |
| `GOTO` | Jump to label |
| `IF` | Conditional branch |
| `INCLUDE` | Insert source file or library |
| `LET` | Declare variable or constant |
| `NEXT` | End FOR loop |
| `PRINT` | Output to screen |
| `REM` | Comment (also `'`) |
| `RETURN` | Return from GOSUB or DEF FN |
| `STEP` | Loop increment in FOR |
| `THEN` | Required after IF condition |
| `TO` | Range separator in FOR |
| `WEND` | End WHILE loop |
| `WHILE` | Begin conditional loop |

---

## I/O
| Keyword | Description |
|---------|-------------|
| `ARGCOUNT` | Returns amount or args. passed to program |
| `ARGS` | Returns specific arg. passed to program |
| `CLS` | Clear screen |
| `COLOR` | Set text foreground/background color |
| `CURPOS` | Read cursor row or col: `CURPOS("row")` / `CURPOS("col")` |
| `GETCONSOLE` | Read character or color from console position |
| `INPUT` | Read user input |
| `ISSET` | TRUE if a variable or constant exists (`ISSET(name$)`); array elements are always FALSE |
| `LINE INPUT` | Read full line including spaces |
| `LOCATE` | Move text cursor |
| `SLEEP` | Pause execution (milliseconds) |

---

## Graphics
| Keyword | Description |
|---------|-------------|
| `B` | Draw box outline instead of line (`LINE (x1,y1)-(x2,y2), color, B`) |
| `BF` | Draw filled box instead of line (`LINE (x1,y1)-(x2,y2), color, BF`) |
| `CIRCLE` | Draw circle or filled circle |
| `DRAWSHAPE` | Render a shape/image to screen |
| `DRAWSTRING` | Render a text to screen |
| `FULLSCREEN` | Toggle borderless fullscreen |
| `HIDESHAPE` | Hide shape without removing |
| `LINE` | Draw line, box outline, or filled box |
| `LOADFONT` | Load font from file or reset to Arial |
| `LOADIMAGE` | Load PNG/BMP (or URL) as shape |
| `LOADSHEET` | Load sprite sheet into array |
| `LOADSHAPE` | Create geometric shape |
| `MOVESHAPE` | Set shape position |
| `PAINT` | Flood fill |
| `POINT` | Read pixel color |
| `PSET` | Draw single pixel |
| `REMOVESHAPE` | Delete shape and free memory |
| `RGB` | Create color value from R, G, B components |
| `ROTATESHAPE` | Rotate shape (absolute degrees) |
| `SAVESCREEN` | Save the graphics screen as a PNG file |
| `SCALESHAPE` | Scale shape |
| `SCREEN` | Initialize graphics window |
| `SCREENLOCK` | Buffer drawing (`ON`) / present frame (`OFF`) |
| `SHOWSHAPE` | Make hidden shape visible |
| `VSYNC` | Enable/disable vertical sync |

---

## Sound
| Keyword | Description |
|---------|-------------|
| `LOADSOUND` | Load sound file, returns ID |
| `SOUNDONCE` | Play sound once (non-blocking) |
| `SOUNDONCEWAIT` | Play sound once (blocking) |
| `SOUNDREPEAT` | Loop sound continuously |
| `SOUNDSTOP` | Stop specific sound |
| `SOUNDSTOPALL` | Stop all sounds |

---

## File
| Keyword | Description |
|---------|-------------|
| `FILEAPPEND` | Append string to file |
| `FILEDELETE` | Delete a file |
| `FILEEXISTS` | Returns 1 if file exists |
| `FILELIST` | Fill array with file names in a folder, return count: `FILELIST(arr$, path$ [, pattern$])`; `*`/`?` wildcards |
| `FILEREAD` | Read file as string or key=value array |
| `FILEWRITE` | Write string or array to file |
| `SHELL` | Run system command, returns output |

---

## Network & Data
| Keyword | Description |
|---------|-------------|
| `ASARRAY` | Parse JSON or XML string into array (format detected from the first character) |
| `ASJSON` | Convert array to JSON string |
| `ASXML` | Convert array to XML string |
| `BASE64DECODE` | Decode Base64 string |
| `BASE64ENCODE` | Encode string to Base64 |
| `GETREQUEST` | Wait for an HTTP request (blocks); returns POST/PUT/PATCH body or GET query string without `?`; `""` on timeout |
| `HTTPERROR` | Error message of the latest HTTPGET/HTTPPOST; `""` if it succeeded |
| `HTTPGET` | HTTP GET request; returns `""` and sets `HTTPERROR` on failure |
| `HTTPPOST` | HTTP POST request; returns `""` and sets `HTTPERROR` on failure |
| `LOADJSON` | Load JSON file into array |
| `LOADXML` | Load XML file into array |
| `SAVEJSON` | Save array as JSON file |
| `SAVEXML` | Save array as XML file |
| `SENDRESPONSE` | Send text response to the pending request (200 OK, CORS enabled) |
| `SHA256` | SHA256 hash (64-char hex) |
| `STARTLISTEN` | Start HTTP server: `STARTLISTEN port [, timeout_ms [, host$]]` (default host 127.0.0.1, `"*"` = all interfaces) |
| `STOPLISTEN` | Stop the HTTP server (silent no-op if none active) |

---

## Math Functions
| Keyword | Description |
|---------|-------------|
| `ABS` | Absolute value |
| `ATAN` | Arc tangent |
| `ATAN2` | Arc tangent of y/x: `ATAN2(y, x)` |
| `BETWEEN` | TRUE if value is within range |
| `CEIL` | Round up |
| `CINT` | Round to nearest integer |
| `CLAMP` | Constrain value to range |
| `COS` | Cosine (radians) |
| `DEG` | Radians to degrees |
| `DISTANCE` | 2D or 3D Euclidean distance |
| `EULER#` | Euler's number (e = 2.71828...) |
| `EXP` | e raised to power |
| `FASTCOS` | Fast cosine (degrees, lookup table) |
| `FASTRAD` | Fast degrees-to-radians |
| `FASTSIN` | Fast sine (degrees, lookup table) |
| `FASTTRIG` | Enable/disable fast trig lookup tables |
| `FLOOR` | Round down |
| `HPI#` | π/2 (90°) |
| `INBETWEEN` | TRUE only if strictly between bounds; unlike `BETWEEN`, equal to a bound is FALSE |
| `INT` | Truncate toward zero |
| `LERP` | Linear interpolation |
| `LOG` | Natural logarithm |
| `MAX` | Higher of two values |
| `MIN` | Lower of two values |
| `MOD` | Remainder |
| `PI#` | π (3.14159...) |
| `POW` | Power |
| `QPI#` | π/4 (45°) |
| `RAD` | Degrees to radians |
| `RND` | Random integer 0 to n-1 |
| `ROUND` | Standard rounding |
| `SGN` | Sign (-1, 0, 1) |
| `SIN` | Sine (radians) |
| `SQR` | Square root |
| `TAN` | Tangent (radians) |
| `TAU#` | 2π (360°) |

The plain names without `#` (`PI`, `HPI`, `QPI`, `TAU`, `EULER`, `PHI`, `GRAV`, `GRAV_E`) still work and give the same values, but are deprecated since 1.9 — use the `#` forms (see the Built-in Constants table below).

---

## String Functions
| Keyword | Description |
|---------|-------------|
| `ASC` | Character to ASCII code |
| `CHR` | ASCII code to character |
| `FSTRING` | Format a template; `{{-name-}}` placeholders are replaced with variable/constant values |
| `INSTR` | Find substring position |
| `INVERT` | Reverse string |
| `LCASE` | Convert to lowercase |
| `LEFT` | First n characters |
| `LEN` | String length (also array element count) |
| `LTRIM` | Strip leading whitespace |
| `MID` | Substring |
| `REPEAT` | Repeat string n times |
| `REPLACE` | Replace all occurrences |
| `RIGHT` | Last n characters |
| `RTRIM` | Strip trailing whitespace |
| `SAME` | Exact text compare, case-sensitive (1 or 0) |
| `SPLIT` | Split string into array |
| `SRAND` | Random alphanumeric string |
| `STR` | Number to string |
| `TRIM` | Strip leading and trailing whitespace |
| `UCASE` | Convert to uppercase |
| `VAL` | String to number |

---

## Input & Mouse
| Keyword | Description |
|---------|-------------|
| `INKEY` | Non-blocking key check |
| `KEYDOWN` | TRUE if key is held (graphics mode only) |
| `MOUSEMIDDLE` | 1 if middle button pressed (graphics mode) |
| `MOUSEHIDE` | Hide mouse cursor (graphics mode) |
| `MOUSELEFT` | 1 if left button pressed (graphics mode) |
| `MOUSERIGHT` | 1 if right button pressed (graphics mode) |
| `MOUSESHOW` | Show mouse cursor (graphics mode) |
| `MOUSEWHEEL` | Wheel notches since the last call, + = up (graphics mode) |
| `MOUSEX` | Mouse cursor X position (graphics mode) |
| `MOUSEY` | Mouse cursor Y position (graphics mode) |
| `WAITKEY` | Block until key pressed |

---

## Gamepad

Works in console and graphics mode. A pad that is not connected reads as
"nothing pressed" (FALSE / 0 / `""`) — no error is raised, so games need no guard code.

| Keyword | Description |
|---------|-------------|
| `GAMEPADS` | Number of connected pads (`GAMEPADS()`) |
| `PADAXIS` | Axis value: sticks -1..1, triggers 0..1 (`PADAXIS(pad, PAD_LX#)`) |
| `PADBUTTON` | 1 if button is pressed (`PADBUTTON(pad, PAD_A#)`) |
| `PADNAME` | Controller name or `""` (`PADNAME(pad)`) |
| `PADRUMBLE` | Rumble the pad: `PADRUMBLE pad, strength, ms` (parentheses optional) |

---

## Arrays
| Keyword | Description |
|---------|-------------|
| `ARRKEY` | Key at 0-based index in insertion order: `ARRKEY(arr$(), i)`; pairs with `LEN(arr$())` for loops |
| `DELARRAY` | Remove entire array |
| `DELKEY` | Remove one array element |
| `HASKEY` | 1 if array element exists |
| `JOIN` | Merge two arrays; src2$ overwrites src1$ on conflict |
| `ROWCOUNT` | Return the size of array in first dimension |

---

## Time
| Keyword | Description |
|---------|-------------|
| `TICKS` | Milliseconds since program start |
| `TIME` | Current date/time as formatted string |

---

## Logic
| Keyword | Description |
|---------|-------------|
| `AND` | Logical AND |
| `FALSE` | 0 |
| `NOT` | Logical NOT |
| `OFF` | Alias for FALSE (used with SCREENLOCK, VSYNC) |
| `ON` | Alias for TRUE (used with SCREENLOCK, VSYNC) |
| `OR` | Logical OR |
| `TRUE` | 1 |

---

## Built-in Constants
These are auto-initialized at startup — no `LET` required.

| Constant | Value |
|----------|-------|
| `BBVER#` | BazzBasic version string (e.g. `"1.1d"`) |
| `BBBUILD#` | Interpreter build time, `"dd-mm-yyyy hh:mm:ss"` |
| `PRG_ROOT#` | Program base directory path (ends with a directory separator) |
| `TRUE` | 1 |
| `FALSE` | 0 |
| `PI#` | 3.141592653589793 |
| `HPI#` | 1.5707963267948966 (π/2) |
| `QPI#` | 0.7853981633974483 (π/4) |
| `TAU#` | 6.283185307179586 (2π) |
| `EULER#` | 2.718281828459045 (e) |
| `AU#` | 149597870700 (astronomical unit in metres, exact — IAU 2012) |
| `PHI#` | 1.618033988749895 (golden ratio) |
| `GRAV#` | 6.6743E-11 (gravitational constant, m^3 kg^-1 s^-2) |
| `GRAV_E#` | 9.80665 (standard gravity on Earth, m/s^2) |
| `BLACK#` | 0xFF000000 (0, 0, 0) |
| `WHITE#` | 0xFFFFFFFF (255, 255, 255) |
| `RED#` | 0xFFFF0000 (255, 0, 0) |
| `GREEN#` | 0xFF00FF00 (0, 255, 0) |
| `BLUE#` | 0xFF0000FF (0, 0, 255) |
| `YELLOW#` | 0xFFFFFF00 (255, 255, 0) |
| `CYAN#` | 0xFF00FFFF (0, 255, 255) |
| `MAGENTA#` | 0xFFFF00FF (255, 0, 255) |
| `GRAY#` | 0xFF808080 (128, 128, 128) |
| `ORANGE#` | 0xFFFFA500 (255, 165, 0) |
| `TRANSPARENT#` | 0x00000000 (0, 0, 0, alpha 0) |

### Keyboard constants
`KEY_UP#` `KEY_DOWN#` `KEY_LEFT#` `KEY_RIGHT#`  
`KEY_ESC#` `KEY_ENTER#` `KEY_SPACE#` `KEY_TAB#` `KEY_BACKSPACE#`  
`KEY_INSERT#` `KEY_DELETE#` `KEY_HOME#` `KEY_END#` `KEY_PGUP#` `KEY_PGDN#`  
`KEY_F1#` … `KEY_F12#`  
`KEY_A#` … `KEY_Z#`  
`KEY_0#` … `KEY_9#`  
`KEY_NUMPAD0#` … `KEY_NUMPAD9#` `KEY_NUMPAD_PLUS#` `KEY_NUMPAD_MINUS#` `KEY_NUMPAD_MUL#` `KEY_NUMPAD_DIV#` `KEY_NUMPAD_DOT#`  
`KEY_LSHIFT#` `KEY_RSHIFT#` `KEY_LCTRL#` `KEY_RCTRL#` `KEY_LALT#` `KEY_RALT#` `KEY_LWIN#` `KEY_RWIN#`  
`KEY_COMMA#` `KEY_DOT#` `KEY_MINUS#` `KEY_EQUALS#` `KEY_SLASH#` `KEY_BACKSLASH#` `KEY_GRAVE#` `KEY_LBRACKET#` `KEY_RBRACKET#` `KEY_SEP#`

### Gamepad constants

Buttons (use with `PADBUTTON(pad, PAD_A#)`):  
`PAD_A#` `PAD_B#` `PAD_X#` `PAD_Y#` `PAD_BACK#` `PAD_GUIDE#` `PAD_START#`  
`PAD_LSTICK#` `PAD_RSTICK#` `PAD_LB#` `PAD_RB#` `PAD_UP#` `PAD_DOWN#` `PAD_LEFT#` `PAD_RIGHT#` `PAD_MISC#` `PAD_TOUCHPAD#`  

Axes (use with `PADAXIS(pad, PAD_LX#)`):  
`PAD_LX#` `PAD_LY#` `PAD_RX#` `PAD_RY#` `PAD_LT#` `PAD_RT#`

Button labels follow the Xbox layout; on PlayStation: A=Cross, B=Circle, X=Square, Y=Triangle.

---

## Command Line

Switches for `BazzBasic.exe` itself — not language keywords.

| Switch | Description |
|--------|-------------|
| `-exe` | Compile a program to a standalone .exe: `BazzBasic.exe -exe program.bas` |
| `-lib` | Compile a library to .bb: `BazzBasic.exe -lib library.bas` |
| `-v` | Show version |
| `-version` | Show version (alias of `-v`) |
