text
stringlengths
0
275
```
| Function/Command | Description |
|-----------------|-------------|
| `LEN(arr$())` | Element count (note empty parens) |
| `HASKEY(arr$(key))` | 1 if exists, 0 if not |
| `DELKEY arr$(key)` | Remove one element |
| `DELARRAY arr$` | Remove entire array (can re-DIM after) |
**Always check with `HASKEY` before reading uninitialized elements.**
---
## Control Flow
```basic
' Block IF
IF score$ >= 90 THEN
PRINT "A"
ELSEIF score$ >= 80 THEN
PRINT "B"
ELSE
PRINT "F"
END IF ' ENDIF also works
' One-line IF (GOTO/GOSUB only)
IF lives$ = 0 THEN GOTO [game_over]
IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [play]
' FOR (auto-declares variable)
FOR i$ = 1 TO 10 STEP 2 : PRINT i$ : NEXT
FOR i$ = 10 TO 1 STEP -1 : PRINT i$ : NEXT
' WHILE
WHILE x$ < 100 : x$ = x$ * 2 : WEND
' Labels, GOTO, GOSUB
[start]
GOSUB [sub:init]
GOTO [main]
[sub:init]
LET x$ = 0
RETURN
' Dynamic jump (variable must contain "[label]" with brackets)
LET target$ = "[menu]"
GOTO target$
' Other
SLEEP 2000 ' Pause ms
END ' Terminate program
```
---
## I/O
| Command | Description |
|---------|-------------|
| `PRINT expr; expr` | `;` = no space, `,` = tab |
| `PRINT "text";` | Trailing `;` suppresses newline |
| `INPUT "prompt", var$` | Splits on whitespace/comma |
| `INPUT "prompt", a$, b$` | Multiple values |
| `LINE INPUT "prompt", var$` | Read entire line with spaces |
| `CLS` | Clear screen |
| `LOCATE row, col` | Move cursor (1-based) |
| `COLOR fg, bg` | Text colors (0–15 palette) |
| `SHELL("cmd")` | Run shell command, returns output |
| `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
**Escape sequences in strings:** `\"` `\n` `\t` `\\`
### Keyboard Input
| Function | Returns | Notes |
|----------|---------|-------|
| `INKEY` | Key value or 0 | Non-blocking |
| `KEYDOWN(key#)` | TRUE/FALSE | Held-key detection; **graphics mode only** |
| `WAITKEY(key#, ...)` | Key value | Blocks until key pressed; `WAITKEY()` = any key |
### Mouse (graphics mode only)
`MOUSEX`, `MOUSEY` — cursor position
`MOUSELEFT`, `MOUSERIGHT`, `MOUSEMIDDLE` — 1 if pressed, 0 otherwise
### Console Read
`GETCONSOLE(row, col, type)` — type: 0=char (ASCII), 1=fg color, 2=bg color
---
## User-Defined Functions
```basic
' Define BEFORE calling. Name must end with $.
DEF FN Clamp$(val$, lo$, hi$)
IF val$ < lo$ THEN RETURN lo$
IF val$ > hi$ THEN RETURN hi$
RETURN val$
END DEF
PRINT FN Clamp$(5, 1, 10) ' ✓ OK — return value used