text stringlengths 0 721 |
|---|
```basic |
LET x$ = 1 |
x$ += 5 ' add |
x$ -= 3 ' subtract |
x$ *= 2 ' multiply |
x$ /= 4 ' divide |
LET s$ = "Hello" |
s$ += " World" ' string concatenation |
``` |
**Scope:** All main-code variables share one scope (IF, FOR, and WHILE do NOT create new scope). |
Main-code variables ($) are NOT accessible inside DEF FN |
`DEF FN` functions are fully isolated — only global constants (`#`) accessible inside. |
**Comparison:** `"123" = 123` is TRUE (cross-type), but keep types consistent for speed. |
--- |
### Built-in Constants |
- **Boolean:** `TRUE`, `FALSE` |
- **Math:** `PI#`, `HPI#` (π/2 = 90°), `QPI#` (π/4 = 45°), `TAU#` (2π = 360°), `EULER#` (e) — `#` suffix required |
- **System:** `PRG_ROOT#` (program base directory path) |
- **Keyboard:** `KEY_ESC#`, `KEY_ENTER#`, `KEY_SPACE#`, `KEY_UP#`, `KEY_DOWN#`, `KEY_LEFT#`, `KEY_RIGHT#`, `KEY_F1#`…`KEY_F12#`, `KEY_A#`…`KEY_Z#`, `KEY_0#`…`KEY_9#`, `KEY_LSHIFT#`, `KEY_LCTRL#`, etc. |
--- |
## Arrays |
BazzBasic arrays are fully dynamic and support numeric, string, or mixed indexing. |
```basic |
DIM scores$ ' Declare (required before use) |
DIM a$, b$, c$ ' Multiple |
scores$(0) = 95 ' Numeric indices are 0-based. |
scores$("name") = "Alice" ' String keys are associative and unordered. |
matrix$(0, 1) = "A2" ' Multi-dimensional |
DIM sounds$ |
sounds$("guns", "shotgun_shoot") = "shoot_shotgun.wav" |
sounds$("guns", "shotgun_reload") = "reload_shotgun.wav" |
sounds$("guns", "ak47_shoot") = "shoot_ak47.wav" |
sounds$("guns", "ak47_reload") = "reload_ak47.wav" |
sounds$("food", "ham_eat") = "eat_ham.wav" |
PRINT LEN(sounds$()) ' 5 as full size of arrayas there is total of 5 values in array |
PRINT ROWCOUNT(sounds$()) ' 2, "guns" & "food" |
``` |
| Function/Command | Description | |
|-----------------|-------------| |
| `LEN(arr$())` | Total element count (LEN counts all nested elements across all dimensions) | |
| `ROWCOUNT(arr$())` | Count of first-dimension rows — use this for FOR loops over multi-dim arrays | |
| `HASKEY(arr$(key))` | 1 if exists, 0 if not | |
| `DELKEY arr$(key)` | Remove one element | |
| `DELARRAY arr$` | Remove entire array (can re-DIM after) | |
| `JOIN dest$, src1$, src2$` | Merge two arrays; `src2$` keys overwrite `src1$`. Use empty `src1$` as `COPYARRAY`. | |
**JOIN** Matching keys from src2$ overwrite src1$ at the same level |
**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 |
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] |
' Avoid jumping into the middle of logical blocks (e.g. inside IF/WHILE) |
GOTO [start] |
[sub:init] |
LET x$ = 0 |
RETURN |
' Dynamic jump (variable must contain "[label]" with brackets) |
LET target$ = "[menu]" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.