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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# METADATA:
|
| 2 |
+
|
| 3 |
+
Name: BazzBasic
|
| 4 |
+
|
| 5 |
+
Description: BazzBasic BASIC interpreter language reference. Use when writing, debugging, or explaining BazzBasic code (.bas files). Triggers on BazzBasic syntax, BASIC programming with $ and # suffixes, SDL2 graphics in BASIC, or references to BazzBasic interpreter features
|
| 6 |
+
|
| 7 |
+
About: BazzBasic is built around one simple idea: starting programming should feel nice and even fun. Ease of learning, comfort of exploration and small but important moments of success. Just like the classic BASICs of decades past, but with a fresh and modern feel.
|
| 8 |
+
|
| 9 |
+
Purpose: This guide has been provided with the idea that it would be easy and efficient for a modern AI to use this guide and through this either guide a new programmer to the secrets of BazzBasic or, if necessary, generate code himself.
|
| 10 |
+
|
| 11 |
+
Version: This guide is written for BazzBasic version 1.1d and is updated 26.03.2026 Finnish time.
|
| 12 |
+
|
| 13 |
+
# END METADATA
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# BazzBasic Language Reference
|
| 18 |
+
**Version:** 1.1b (March 2026) | **Author:** Kristian Virtanen (EkBass) | **Platform:** Windows x64
|
| 19 |
+
**GitHub:** https://github.com/EkBass/BazzBasic
|
| 20 |
+
**Manual:** https://ekbass.github.io/BazzBasic/manual/#/
|
| 21 |
+
**Examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples
|
| 22 |
+
**Rosetta Code:** https://rosettacode.org/wiki/Category:BazzBasic
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## ⚠️ Critical Rules — Read First
|
| 28 |
+
|
| 29 |
+
| Rule | Detail |
|
| 30 |
+
|------|--------|
|
| 31 |
+
| Variables end with `$` | `name$`, `score$`, `x$` |
|
| 32 |
+
| Constants end with `#` | `MAX#`, `PI#`, `TITLE#` |
|
| 33 |
+
| Arrays declared with `DIM`, end with `$` | `DIM items$` |
|
| 34 |
+
| First use of variable requires `LET` | `LET x$ = 0` — after that `x$ = x$ + 1` |
|
| 35 |
+
| FOR and INPUT auto-declare, no LET needed | `FOR i$ = 1 TO 10` |
|
| 36 |
+
| Functions defined **before** they are called | Put at top or INCLUDE |
|
| 37 |
+
| Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
|
| 38 |
+
| Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
|
| 39 |
+
| Arrays **cannot** be passed to functions | Pass individual elements by value |
|
| 40 |
+
| Case-insensitive | `PRINT`, `print`, `Print` all work |
|
| 41 |
+
| `+` operator does both add and concatenate | `"Hi" + " " + name$` |
|
| 42 |
+
| Division always returns float | `10 / 3` → `3.333...` |
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
## ABOUT
|
| 48 |
+
BazzBasic is built around one simple idea: starting programming should feel nice and even fun.
|
| 49 |
+
|
| 50 |
+
Ease of learning, comfort of exploration and small but important moments of success.
|
| 51 |
+
|
| 52 |
+
Just like the classic BASICs of decades past, but with a fresh and modern feel.
|
| 53 |
+
|
| 54 |
+
## STORY
|
| 55 |
+
Although over the years, as my own skills have grown, I have moved on to more versatile and modern languages, BASIC has always been something that has been fun to try out many different things with.
|
| 56 |
+
|
| 57 |
+
Sometimes it's great to just make a simple adventure game again, a lottery machine, a quiz, or even just those balls bouncing on the screen.
|
| 58 |
+
|
| 59 |
+
BazzBasic was created with this in mind.
|
| 60 |
+
|
| 61 |
+
I wanted to create a language that makes it easy for you to give free rein to your curiosity and program something.
|
| 62 |
+
|
| 63 |
+
And when you finish your first little game, you may crave something bigger and better.
|
| 64 |
+
|
| 65 |
+
Maybe one day you will move on to another programming language, but then BazzBasic will have succeeded in doing what it was intended for.
|
| 66 |
+
|
| 67 |
+
To arouse your curiosity.
|
| 68 |
+
|
| 69 |
+
## Variables & Constants
|
| 70 |
+
|
| 71 |
+
```basic
|
| 72 |
+
LET a$ ' Declare without value
|
| 73 |
+
LET name$ = "Alice" ' String variable
|
| 74 |
+
LET score$ = 0 ' Numeric variable
|
| 75 |
+
LET x$, y$, z$ = 10 ' Multiple declaration
|
| 76 |
+
LET PI# = 3.14159 ' Constant (immutable)
|
| 77 |
+
LET TITLE# = "My Game" ' String constant
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
**Scope:** All main-code variables share one scope (even inside IF blocks).
|
| 81 |
+
`DEF FN` functions are fully isolated — only global constants (`#`) accessible inside.
|
| 82 |
+
|
| 83 |
+
**Comparison:** `"123" = 123` is TRUE (cross-type), but keep types consistent for speed.
|
| 84 |
+
|
| 85 |
+
### Built-in Constants
|
| 86 |
+
- **Boolean:** `TRUE`, `FALSE`
|
| 87 |
+
- **Math:** `PI`, `HPI` (π/2 = 90°), `QPI` (π/4 = 45°), `TAU` (2π = 360°), `EULER` (e)
|
| 88 |
+
- **System:** `ROOT#` (program base directory path)
|
| 89 |
+
- **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.
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
## Arrays
|
| 94 |
+
|
| 95 |
+
```basic
|
| 96 |
+
DIM scores$ ' Declare (required before use)
|
| 97 |
+
DIM a$, b$, c$ ' Multiple
|
| 98 |
+
scores$(0) = 95 ' Numeric index (0-based)
|
| 99 |
+
scores$("name") = "Alice" ' String key (associative)
|
| 100 |
+
matrix$(0, 1) = "A2" ' Multi-dimensional
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
| Function/Command | Description |
|
| 104 |
+
|-----------------|-------------|
|
| 105 |
+
| `LEN(arr$())` | Element count (note empty parens) |
|
| 106 |
+
| `HASKEY(arr$(key))` | 1 if exists, 0 if not |
|
| 107 |
+
| `DELKEY arr$(key)` | Remove one element |
|
| 108 |
+
| `DELARRAY arr$` | Remove entire array (can re-DIM after) |
|
| 109 |
+
|
| 110 |
+
**Always check with `HASKEY` before reading uninitialized elements.**
|
| 111 |
+
|
| 112 |
+
---
|
| 113 |
+
|
| 114 |
+
## Control Flow
|
| 115 |
+
|
| 116 |
+
```basic
|
| 117 |
+
' Block IF
|
| 118 |
+
IF score$ >= 90 THEN
|
| 119 |
+
PRINT "A"
|
| 120 |
+
ELSEIF score$ >= 80 THEN
|
| 121 |
+
PRINT "B"
|
| 122 |
+
ELSE
|
| 123 |
+
PRINT "F"
|
| 124 |
+
END IF ' ENDIF also works
|
| 125 |
+
|
| 126 |
+
' One-line IF (GOTO/GOSUB only)
|
| 127 |
+
IF lives$ = 0 THEN GOTO [game_over]
|
| 128 |
+
IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [play]
|
| 129 |
+
|
| 130 |
+
' FOR (auto-declares variable)
|
| 131 |
+
FOR i$ = 1 TO 10 STEP 2 : PRINT i$ : NEXT
|
| 132 |
+
FOR i$ = 10 TO 1 STEP -1 : PRINT i$ : NEXT
|
| 133 |
+
|
| 134 |
+
' WHILE
|
| 135 |
+
WHILE x$ < 100 : x$ = x$ * 2 : WEND
|
| 136 |
+
|
| 137 |
+
' Labels, GOTO, GOSUB
|
| 138 |
+
[start]
|
| 139 |
+
GOSUB [sub:init]
|
| 140 |
+
GOTO [main]
|
| 141 |
+
|
| 142 |
+
[sub:init]
|
| 143 |
+
LET x$ = 0
|
| 144 |
+
RETURN
|
| 145 |
+
|
| 146 |
+
' Dynamic jump (variable must contain "[label]" with brackets)
|
| 147 |
+
LET target$ = "[menu]"
|
| 148 |
+
GOTO target$
|
| 149 |
+
|
| 150 |
+
' Other
|
| 151 |
+
SLEEP 2000 ' Pause ms
|
| 152 |
+
END ' Terminate program
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
---
|
| 156 |
+
|
| 157 |
+
## I/O
|
| 158 |
+
|
| 159 |
+
| Command | Description |
|
| 160 |
+
|---------|-------------|
|
| 161 |
+
| `PRINT expr; expr` | `;` = no space, `,` = tab |
|
| 162 |
+
| `PRINT "text";` | Trailing `;` suppresses newline |
|
| 163 |
+
| `INPUT "prompt", var$` | Splits on whitespace/comma |
|
| 164 |
+
| `INPUT "prompt", a$, b$` | Multiple values |
|
| 165 |
+
| `LINE INPUT "prompt", var$` | Read entire line with spaces |
|
| 166 |
+
| `CLS` | Clear screen |
|
| 167 |
+
| `LOCATE row, col` | Move cursor (1-based) |
|
| 168 |
+
| `COLOR fg, bg` | Text colors (0–15 palette) |
|
| 169 |
+
| `SHELL("cmd")` | Run shell command, returns output |
|
| 170 |
+
| `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
|
| 171 |
+
|
| 172 |
+
**Escape sequences in strings:** `\"` `\n` `\t` `\\`
|
| 173 |
+
|
| 174 |
+
### Keyboard Input
|
| 175 |
+
| Function | Returns | Notes |
|
| 176 |
+
|----------|---------|-------|
|
| 177 |
+
| `INKEY` | Key value or 0 | Non-blocking |
|
| 178 |
+
| `KEYDOWN(key#)` | TRUE/FALSE | Held-key detection; **graphics mode only** |
|
| 179 |
+
| `WAITKEY(key#, ...)` | Key value | Blocks until key pressed; `WAITKEY()` = any key |
|
| 180 |
+
|
| 181 |
+
### Mouse (graphics mode only)
|
| 182 |
+
`MOUSEX`, `MOUSEY` — cursor position
|
| 183 |
+
`MOUSELEFT`, `MOUSERIGHT`, `MOUSEMIDDLE` — 1 if pressed, 0 otherwise
|
| 184 |
+
|
| 185 |
+
### Console Read
|
| 186 |
+
`GETCONSOLE(row, col, type)` — type: 0=char (ASCII), 1=fg color, 2=bg color
|
| 187 |
+
|
| 188 |
+
---
|
| 189 |
+
|
| 190 |
+
## User-Defined Functions
|
| 191 |
+
|
| 192 |
+
```basic
|
| 193 |
+
' Define BEFORE calling. Name must end with $.
|
| 194 |
+
DEF FN Clamp$(val$, lo$, hi$)
|
| 195 |
+
IF val$ < lo$ THEN RETURN lo$
|
| 196 |
+
IF val$ > hi$ THEN RETURN hi$
|
| 197 |
+
RETURN val$
|
| 198 |
+
END DEF
|
| 199 |
+
|
| 200 |
+
PRINT FN Clamp$(5, 1, 10) ' ✓ OK — return value used
|
| 201 |
+
LET v$ = FN Clamp$(15, 0, 10) ' ✓ OK
|
| 202 |
+
FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
- Isolated scope: no access to global variables, only global constants (`#`)
|
| 206 |
+
- Parameters passed **by value**
|
| 207 |
+
- Labels inside functions are local — GOTO/GOSUB cannot jump outside
|
| 208 |
+
- Supports recursion
|
| 209 |
+
- Use `INCLUDE` to load functions from separate files if many
|
| 210 |
+
|
| 211 |
+
---
|
| 212 |
+
|
| 213 |
+
## String Functions
|
| 214 |
+
|
| 215 |
+
| Function | Description |
|
| 216 |
+
|----------|-------------|
|
| 217 |
+
| `ASC(s$)` | ASCII code of first char |
|
| 218 |
+
| `CHR(n)` | Character from ASCII code |
|
| 219 |
+
| `INSTR(s$, search$)` | Position (1-based), 0=not found |
|
| 220 |
+
| `INSTR(start, s$, search$)` | Search from position |
|
| 221 |
+
| `INVERT(s$)` | Reverse string |
|
| 222 |
+
| `LCASE(s$)` / `UCASE(s$)` | Lower / upper case |
|
| 223 |
+
| `LEFT(s$, n)` / `RIGHT(s$, n)` | First/last n chars |
|
| 224 |
+
| `LEN(s$)` | String length |
|
| 225 |
+
| `LTRIM(s$)` / `RTRIM(s$)` / `TRIM(s$)` | Strip whitespace |
|
| 226 |
+
| `MID(s$, start)` | Substring from start (1-based) |
|
| 227 |
+
| `MID(s$, start, len)` | Substring with length |
|
| 228 |
+
| `REPEAT(s$, n)` | Repeat string n times |
|
| 229 |
+
| `REPLACE(s$, a$, b$)` | Replace a$ with b$ in s$ |
|
| 230 |
+
| `SPLIT(arr$, s$, sep$)` | Split into array, returns count |
|
| 231 |
+
| `SRAND(n)` | Random alphanumeric string of length n |
|
| 232 |
+
| `STR(n)` | Number to string |
|
| 233 |
+
| `VAL(s$)` | String to number |
|
| 234 |
+
| `SHA256(s$)` | SHA256 hash (64-char hex) |
|
| 235 |
+
| `BASE64ENCODE(s$)` / `BASE64DECODE(s$)` | Base64 encode/decode |
|
| 236 |
+
|
| 237 |
+
---
|
| 238 |
+
|
| 239 |
+
## Math Functions
|
| 240 |
+
|
| 241 |
+
| Function | Description |
|
| 242 |
+
|----------|-------------|
|
| 243 |
+
| `ABS(n)` | Absolute value |
|
| 244 |
+
| `ATAN(n)` | Arc tangent |
|
| 245 |
+
| `BETWEEN(n, min, max)` | TRUE if min ≤ n ≤ max |
|
| 246 |
+
| `CEIL(n)` / `FLOOR(n)` | Round up / down |
|
| 247 |
+
| `CINT(n)` | Round to nearest integer |
|
| 248 |
+
| `CLAMP(n, min, max)` | Constrain n to [min, max] |
|
| 249 |
+
| `COS(n)` / `SIN(n)` / `TAN(n)` | Trig (radians) |
|
| 250 |
+
| `DEG(rad)` / `RAD(deg)` | Radians ↔ degrees |
|
| 251 |
+
| `DISTANCE(x1,y1, x2,y2)` | 2D Euclidean distance |
|
| 252 |
+
| `DISTANCE(x1,y1,z1, x2,y2,z2)` | 3D Euclidean distance |
|
| 253 |
+
| `EXP(n)` | e^n |
|
| 254 |
+
| `INT(n)` | Truncate toward zero |
|
| 255 |
+
| `LERP(start, end, t)` | Linear interpolation (t: 0.0–1.0) |
|
| 256 |
+
| `LOG(n)` | Natural logarithm |
|
| 257 |
+
| `MAX(a, b)` / `MIN(a, b)` | Larger / smaller of two |
|
| 258 |
+
| `MOD(a, b)` | Remainder |
|
| 259 |
+
| `POW(base, exp)` | Power |
|
| 260 |
+
| `RND(n)` | Random integer 0 to n-1 |
|
| 261 |
+
| `ROUND(n)` | Standard rounding |
|
| 262 |
+
| `SGN(n)` | Sign: -1, 0, or 1 |
|
| 263 |
+
| `SQR(n)` | Square root |
|
| 264 |
+
|
| 265 |
+
**Math constants:** `PI`, `HPI` (PI/2), `QPI` (PI/4), `TAU` (PI*2), `EULER`
|
| 266 |
+
|
| 267 |
+
---
|
| 268 |
+
|
| 269 |
+
## Graphics
|
| 270 |
+
|
| 271 |
+
```basic
|
| 272 |
+
SCREEN 12 ' 640×480 VGA (recommended)
|
| 273 |
+
SCREEN 0, 800, 600 ' Custom size
|
| 274 |
+
SCREEN 0, 1024, 768, "My Game" ' Custom size + title
|
| 275 |
+
FULLSCREEN TRUE ' Borderless fullscreen (graphics only)
|
| 276 |
+
FULLSCREEN FALSE ' Windowed
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
| Mode | Resolution |
|
| 280 |
+
|------|-----------|
|
| 281 |
+
| 1 | 320×200 |
|
| 282 |
+
| 2 | 640×350 |
|
| 283 |
+
| 7 | 320×200 |
|
| 284 |
+
| 9 | 640×350 |
|
| 285 |
+
| 12 | 640×480 ← recommended |
|
| 286 |
+
| 13 | 320×200 |
|
| 287 |
+
|
| 288 |
+
### Drawing Primitives
|
| 289 |
+
```basic
|
| 290 |
+
PSET (x, y), color ' Pixel
|
| 291 |
+
LINE (x1,y1)-(x2,y2), color ' Line
|
| 292 |
+
LINE (x1,y1)-(x2,y2), color, B ' Box outline
|
| 293 |
+
LINE (x1,y1)-(x2,y2), color, BF ' Box filled (FAST — use instead of CLS)
|
| 294 |
+
CIRCLE (cx,cy), radius, color ' Circle outline
|
| 295 |
+
CIRCLE (cx,cy), radius, color, 1 ' Circle filled
|
| 296 |
+
PAINT (x, y), fillColor, borderColor ' Flood fill
|
| 297 |
+
LET c$ = POINT(x, y) ' Read pixel color
|
| 298 |
+
LET col$ = RGB(r, g, b) ' Create color (0–255 each)
|
| 299 |
+
```
|
| 300 |
+
|
| 301 |
+
**Color palette (COLOR command, 0–15):** 0=Black, 1=Blue, 2=Green, 3=Cyan, 4=Red, 5=Magenta, 6=Brown, 7=Lt Gray, 8=Dk Gray, 9=Lt Blue, 10=Lt Green, 11=Lt Cyan, 12=Lt Red, 13=Lt Magenta, 14=Yellow, 15=White
|
| 302 |
+
|
| 303 |
+
### Screen Control
|
| 304 |
+
```basic
|
| 305 |
+
SCREENLOCK ON ' Buffer drawing (start frame)
|
| 306 |
+
SCREENLOCK OFF ' Present buffer (end frame)
|
| 307 |
+
VSYNC(TRUE) ' Enable VSync (default, ~60 FPS)
|
| 308 |
+
VSYNC(FALSE) ' Disable VSync (benchmarking)
|
| 309 |
+
CLS ' Clear screen (slow — prefer LINE BF)
|
| 310 |
+
```
|
| 311 |
+
|
| 312 |
+
### Shapes & Images
|
| 313 |
+
```basic
|
| 314 |
+
' Create shape
|
| 315 |
+
LET id$ = LOADSHAPE("RECTANGLE", w, h, color) ' or "CIRCLE", "TRIANGLE"
|
| 316 |
+
LET img$ = LOADIMAGE("player.png") ' PNG (alpha) or BMP
|
| 317 |
+
LET img$ = LOADIMAGE("https://example.com/a.png") ' Download + load
|
| 318 |
+
|
| 319 |
+
' Sprite sheet — sprites indexed 1-based
|
| 320 |
+
DIM sprites$
|
| 321 |
+
LOADSHEET sprites$, 128, 128, "sheet.png" ' tileW, tileH, file
|
| 322 |
+
MOVESHAPE sprites$(1), x, y ' sprites$(1) = first sprite
|
| 323 |
+
|
| 324 |
+
' Transform
|
| 325 |
+
MOVESHAPE id$, x, y ' Position by center point
|
| 326 |
+
ROTATESHAPE id$, angle ' Degrees (absolute)
|
| 327 |
+
SCALESHAPE id$, scale ' 1.0 = original size
|
| 328 |
+
DRAWSHAPE id$ ' Render to buffer
|
| 329 |
+
SHOWSHAPE id$ / HIDESHAPE id$ ' Toggle visibility
|
| 330 |
+
REMOVESHAPE id$ ' Free memory (always clean up)
|
| 331 |
+
```
|
| 332 |
+
|
| 333 |
+
---
|
| 334 |
+
|
| 335 |
+
## Sound
|
| 336 |
+
|
| 337 |
+
```basic
|
| 338 |
+
LET snd$ = LOADSOUND("jump.wav") ' Load (WAV recommended)
|
| 339 |
+
SOUNDONCE(snd$) ' Play once, non-blocking
|
| 340 |
+
SOUNDONCEWAIT(snd$) ' Play once, wait for finish
|
| 341 |
+
SOUNDREPEAT(snd$) ' Loop continuously
|
| 342 |
+
SOUNDSTOP(snd$) ' Stop specific sound
|
| 343 |
+
SOUNDSTOPALL ' Stop all sounds
|
| 344 |
+
```
|
| 345 |
+
|
| 346 |
+
Load all sounds at startup. Call `SOUNDSTOPALL` before `END`.
|
| 347 |
+
|
| 348 |
+
---
|
| 349 |
+
|
| 350 |
+
## File I/O
|
| 351 |
+
|
| 352 |
+
```basic
|
| 353 |
+
LET data$ = FileRead("file.txt") ' Read as string
|
| 354 |
+
DIM cfg$ : LET cfg$ = FileRead("settings.txt") ' Read as key=value array
|
| 355 |
+
FileWrite "save.txt", data$ ' Create/overwrite
|
| 356 |
+
FileAppend "log.txt", entry$ ' Append
|
| 357 |
+
LET ok$ = FileExists("file.txt") ' 1=exists, 0=not
|
| 358 |
+
FileDelete "temp.dat" ' Delete file
|
| 359 |
+
```
|
| 360 |
+
|
| 361 |
+
**key=value parsing:** When `FileRead` assigns to a `DIM`'d array, lines `key=value` become `arr$("key")`. Lines starting with `#` are comments. Perfect for `.env` files.
|
| 362 |
+
|
| 363 |
+
```basic
|
| 364 |
+
DIM env$
|
| 365 |
+
LET env$ = FileRead(".env")
|
| 366 |
+
LET API_KEY# = env$("OPENAI_API_KEY")
|
| 367 |
+
```
|
| 368 |
+
|
| 369 |
+
**Paths:** Use `/` or `\\` — never single `\` (it's an escape char). Relative paths are from `ROOT#`.
|
| 370 |
+
**FileWrite with array** saves in key=value format (round-trips with FileRead).
|
| 371 |
+
|
| 372 |
+
---
|
| 373 |
+
|
| 374 |
+
## Network
|
| 375 |
+
|
| 376 |
+
```basic
|
| 377 |
+
LET res$ = HTTPGET("https://api.example.com/data")
|
| 378 |
+
LET res$ = HTTPPOST("https://api.example.com/submit", "{""key"":""val""}")
|
| 379 |
+
|
| 380 |
+
' With headers (optional last parameter)
|
| 381 |
+
DIM headers$
|
| 382 |
+
headers$("Authorization") = "Bearer mytoken"
|
| 383 |
+
headers$("Content-Type") = "application/json"
|
| 384 |
+
LET res$ = HTTPGET("https://api.example.com/data", headers$)
|
| 385 |
+
LET res$ = HTTPPOST("https://api.example.com/data", body$, headers$)
|
| 386 |
+
```
|
| 387 |
+
|
| 388 |
+
---
|
| 389 |
+
|
| 390 |
+
## Arrays & JSON
|
| 391 |
+
|
| 392 |
+
Nested JSON maps to comma-separated keys: `data$("player,name")`, `data$("skills,0")`
|
| 393 |
+
|
| 394 |
+
```basic
|
| 395 |
+
' Array → JSON string
|
| 396 |
+
LET json$ = ASJSON(arr$)
|
| 397 |
+
|
| 398 |
+
' JSON string → array (returns element count)
|
| 399 |
+
DIM data$
|
| 400 |
+
LET count$ = ASARRAY(data$, json$)
|
| 401 |
+
|
| 402 |
+
' Load/save JSON files
|
| 403 |
+
LOADJSON arr$, "file.json"
|
| 404 |
+
SAVEJSON arr$, "file.json"
|
| 405 |
+
```
|
| 406 |
+
|
| 407 |
+
---
|
| 408 |
+
|
| 409 |
+
## Fast Trigonometry
|
| 410 |
+
|
| 411 |
+
~20× faster than `SIN(RAD(x))`, 1-degree precision. Uses ~5.6 KB memory.
|
| 412 |
+
|
| 413 |
+
```basic
|
| 414 |
+
FastTrig(TRUE) ' Enable lookup tables (must call first)
|
| 415 |
+
LET x$ = FastCos(45) ' Degrees, auto-normalized 0–359
|
| 416 |
+
LET y$ = FastSin(90)
|
| 417 |
+
LET r$ = FastRad(180) ' Deg→rad (no FastTrig needed)
|
| 418 |
+
FastTrig(FALSE) ' Free memory
|
| 419 |
+
```
|
| 420 |
+
|
| 421 |
+
Use for raycasting, sprite rotation, particle systems, any high-freq trig.
|
| 422 |
+
|
| 423 |
+
---
|
| 424 |
+
|
| 425 |
+
## Libraries & INCLUDE
|
| 426 |
+
|
| 427 |
+
```basic
|
| 428 |
+
INCLUDE "helpers.bas" ' Insert source at this point
|
| 429 |
+
INCLUDE "MathLib.bb" ' Load compiled library
|
| 430 |
+
|
| 431 |
+
' Compile library (functions only — no loose code)
|
| 432 |
+
' bazzbasic.exe -lib MathLib.bas → MathLib.bb
|
| 433 |
+
' Function names auto-prefixed: MATHLIB_functionname$
|
| 434 |
+
PRINT FN MATHLIB_add$(5, 3)
|
| 435 |
+
```
|
| 436 |
+
|
| 437 |
+
Library functions can read main-program constants (`#`). `.bb` files are version-locked.
|
| 438 |
+
|
| 439 |
+
---
|
| 440 |
+
|
| 441 |
+
## Program Structure
|
| 442 |
+
|
| 443 |
+
```basic
|
| 444 |
+
' ---- 1. CONSTANTS (or INCLUDE "constants.bas") ----
|
| 445 |
+
LET SCREEN_W# = 640
|
| 446 |
+
LET SCREEN_H# = 480
|
| 447 |
+
LET MAX_SPEED# = 5
|
| 448 |
+
|
| 449 |
+
' ---- 2. FUNCTIONS (or INCLUDE "functions.bas") ----
|
| 450 |
+
DEF FN Clamp$(v$, lo$, hi$)
|
| 451 |
+
IF v$ < lo$ THEN RETURN lo$
|
| 452 |
+
IF v$ > hi$ THEN RETURN hi$
|
| 453 |
+
RETURN v$
|
| 454 |
+
END DEF
|
| 455 |
+
|
| 456 |
+
' ---- 3. INIT (declare ALL variables here, not inside loops) ----
|
| 457 |
+
' Performance: variables declared outside loops avoid repeated existence checks.
|
| 458 |
+
[inits]
|
| 459 |
+
SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
|
| 460 |
+
LET x$ = 320
|
| 461 |
+
LET y$ = 240
|
| 462 |
+
LET running$ = TRUE
|
| 463 |
+
|
| 464 |
+
' ---- 4. MAIN LOOP ----
|
| 465 |
+
[main]
|
| 466 |
+
WHILE running$
|
| 467 |
+
IF INKEY = KEY_ESC# THEN running$ = FALSE
|
| 468 |
+
GOSUB [sub:update]
|
| 469 |
+
GOSUB [sub:draw]
|
| 470 |
+
SLEEP 16
|
| 471 |
+
WEND
|
| 472 |
+
SOUNDSTOPALL
|
| 473 |
+
END
|
| 474 |
+
|
| 475 |
+
' ---- 5. SUBROUTINES (or INCLUDE "subs.bas") ----
|
| 476 |
+
[sub:update]
|
| 477 |
+
IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED#
|
| 478 |
+
IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED#
|
| 479 |
+
RETURN
|
| 480 |
+
|
| 481 |
+
[sub:draw]
|
| 482 |
+
SCREENLOCK ON
|
| 483 |
+
LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
|
| 484 |
+
CIRCLE (x$, y$), 10, RGB(0, 255, 0), 1
|
| 485 |
+
SCREENLOCK OFF
|
| 486 |
+
RETURN
|
| 487 |
+
```
|
| 488 |
+
|
| 489 |
+
**Key conventions:**
|
| 490 |
+
- Variables: `camelCase$` | Constants: `UPPER_SNAKE_CASE#` | Functions: `PascalCase$`
|
| 491 |
+
- Labels: `[gameLoop]` for jump targets, `[sub:name]` for subroutines
|
| 492 |
+
- Image/sound IDs that never change → use constants: `LET MY_IMG# = LOADIMAGE("x.png")`
|
| 493 |
+
- Group many image/sound IDs → use arrays: `DIM sprites$` / `sprites$("player") = LOADIMAGE(...)`
|
| 494 |
+
|
| 495 |
+
---
|
| 496 |
+
|
| 497 |
+
## Performance Tips
|
| 498 |
+
|
| 499 |
+
- `LINE (0,0)-(W,H), 0, BF` to clear — much faster than `CLS`
|
| 500 |
+
- Always wrap draw code in `SCREENLOCK ON` / `SCREENLOCK OFF`
|
| 501 |
+
- Store `RGB()` results in constants/variables — don't call RGB in hot loops
|
| 502 |
+
- Declare all variables in `[inits]`, not inside loops or subroutines
|
| 503 |
+
- Use `FastTrig` for any loop calling trig hundreds of times per frame
|
| 504 |
+
- `SLEEP 16` in game loop → ~60 FPS
|