Delete BazzBasic-AI-guide.txt
Browse files- BazzBasic-AI-guide.txt +0 -603
BazzBasic-AI-guide.txt
DELETED
|
@@ -1,603 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
name: bazzbasic
|
| 3 |
-
description: "BazzBasic BASIC interpreter language reference. Use when writing, debugging, or explaining BazzBasic code (.bas files). Triggers on: BazzBasic syntax, $ and # variable suffixes, SDL2 graphics in BASIC, SCREEN/DRAWSHAPE/LOADIMAGE commands, DEF FN functions, BazzBasic file I/O, sound commands, or any question about BazzBasic features. Always use this skill before writing any BazzBasic code."
|
| 4 |
-
---
|
| 5 |
-
|
| 6 |
-
# BazzBasic Language Reference
|
| 7 |
-
**Version:** 1.3b | **Author:** Kristian Virtanen (EkBass) | **Platform:** Windows x64
|
| 8 |
-
**GitHub:** https://github.com/EkBass/BazzBasic
|
| 9 |
-
**Manual:** https://ekbass.github.io/BazzBasic/manual/#/
|
| 10 |
-
**Examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples
|
| 11 |
-
**Rosetta Code:** https://rosettacode.org/wiki/Category:BazzBasic
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
---
|
| 15 |
-
|
| 16 |
-
## ⚠️ Critical Rules — Read First
|
| 17 |
-
|
| 18 |
-
| Rule | Detail |
|
| 19 |
-
|------|--------|
|
| 20 |
-
| Variables end with `$` | `name$`, `score$`, `x$` |
|
| 21 |
-
| Constants end with `#` | `MAX#`, `PI#`, `TITLE#` |
|
| 22 |
-
| Arrays declared with `DIM`, end with `$` | `DIM items$` |
|
| 23 |
-
| First use of variable requires `LET` | `LET x$ = 0` — after that `x$ = x$ + 1` |
|
| 24 |
-
| FOR and INPUT auto-declare, no LET needed | `FOR i$ = 1 TO 10` |
|
| 25 |
-
| Functions defined **before** they are called | Put at top or INCLUDE |
|
| 26 |
-
| Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
|
| 27 |
-
| Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
|
| 28 |
-
| Arrays **cannot** be passed to functions directly | Pass individual elements, or serialize to JSON string — see *Passing Arrays to Functions* section |
|
| 29 |
-
| Case-insensitive | `PRINT`, `print`, `Print` all work |
|
| 30 |
-
| `+` operator does both add and concatenate | `"Hi" + " " + name$` |
|
| 31 |
-
| Division always returns float | `10 / 3` → `3.333...` |
|
| 32 |
-
|
| 33 |
-
---
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
## ABOUT
|
| 37 |
-
BazzBasic is built around one simple idea: starting programming should feel nice and even fun.
|
| 38 |
-
|
| 39 |
-
Ease of learning, comfort of exploration and small but important moments of success.
|
| 40 |
-
|
| 41 |
-
Just like the classic BASICs of decades past, but with a fresh and modern feel.
|
| 42 |
-
|
| 43 |
-
## STORY
|
| 44 |
-
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.
|
| 45 |
-
|
| 46 |
-
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.
|
| 47 |
-
|
| 48 |
-
BazzBasic was created with this in mind.
|
| 49 |
-
|
| 50 |
-
I wanted to create a language that makes it easy for you to give free rein to your curiosity and program something.
|
| 51 |
-
|
| 52 |
-
And when you finish your first little game, you may crave something bigger and better.
|
| 53 |
-
|
| 54 |
-
Maybe one day you will move on to another programming language, but then BazzBasic will have succeeded in doing what it was intended for.
|
| 55 |
-
|
| 56 |
-
To arouse your curiosity.
|
| 57 |
-
|
| 58 |
-
## Variables & Constants
|
| 59 |
-
|
| 60 |
-
```basic
|
| 61 |
-
LET a$ ' Declare without value
|
| 62 |
-
LET name$ = "Alice" ' String variable
|
| 63 |
-
LET score$ = 0 ' Numeric variable
|
| 64 |
-
LET x$, y$, z$ = 10 ' Multiple declaration
|
| 65 |
-
LET PI# = 3.14159 ' Constant (immutable)
|
| 66 |
-
LET TITLE# = "My Game" ' String constant
|
| 67 |
-
```
|
| 68 |
-
|
| 69 |
-
**Compound assignment operators** (variables only — **not** allowed with `#` constants):
|
| 70 |
-
|
| 71 |
-
```basic
|
| 72 |
-
x$ += 5 ' add
|
| 73 |
-
x$ -= 3 ' subtract
|
| 74 |
-
x$ *= 2 ' multiply
|
| 75 |
-
x$ /= 4 ' divide
|
| 76 |
-
s$ += " World" ' string concatenation
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
**Scope:** All main-code variables share one scope (even inside IF blocks).
|
| 80 |
-
`DEF FN` functions are fully isolated — only global constants (`#`) accessible inside.
|
| 81 |
-
|
| 82 |
-
**Comparison:** `"123" = 123` is TRUE (cross-type), but keep types consistent for speed.
|
| 83 |
-
|
| 84 |
-
### Built-in Constants
|
| 85 |
-
- **Boolean:** `TRUE`, `FALSE`
|
| 86 |
-
- **Math:** `PI#`, `HPI#` (π/2 = 90°), `QPI#` (π/4 = 45°), `TAU#` (2π = 360°), `EULER#` (e) — `#` suffix required
|
| 87 |
-
- **System:** `PRG_ROOT#` (program base directory path)
|
| 88 |
-
- **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.
|
| 89 |
-
|
| 90 |
-
---
|
| 91 |
-
|
| 92 |
-
## Arrays
|
| 93 |
-
|
| 94 |
-
```basic
|
| 95 |
-
DIM scores$ ' Declare (required before use)
|
| 96 |
-
DIM a$, b$, c$ ' Multiple
|
| 97 |
-
scores$(0) = 95 ' Numeric index (0-based)
|
| 98 |
-
scores$("name") = "Alice" ' String key (associative)
|
| 99 |
-
matrix$(0, 1) = "A2" ' Multi-dimensional
|
| 100 |
-
```
|
| 101 |
-
|
| 102 |
-
| Function/Command | Description |
|
| 103 |
-
|-----------------|-------------|
|
| 104 |
-
| `LEN(arr$())` | Total element count (note empty parens) |
|
| 105 |
-
| `ROWCOUNT(arr$())` | Count of first-dimension rows — use this for FOR loops over multi-dim arrays |
|
| 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 |
-
| `JOIN dest$, src1$, src2$` | Merge two arrays; `src2$` keys overwrite `src1$`. Use empty `src1$` as `COPYARRAY`. |
|
| 110 |
-
|
| 111 |
-
**Always check with `HASKEY` before reading uninitialized elements.**
|
| 112 |
-
|
| 113 |
-
---
|
| 114 |
-
|
| 115 |
-
## Control Flow
|
| 116 |
-
|
| 117 |
-
```basic
|
| 118 |
-
' Block IF
|
| 119 |
-
IF score$ >= 90 THEN
|
| 120 |
-
PRINT "A"
|
| 121 |
-
ELSEIF score$ >= 80 THEN
|
| 122 |
-
PRINT "B"
|
| 123 |
-
ELSE
|
| 124 |
-
PRINT "F"
|
| 125 |
-
END IF ' ENDIF also works
|
| 126 |
-
|
| 127 |
-
' One-line IF (GOTO/GOSUB only)
|
| 128 |
-
IF lives$ = 0 THEN GOTO [game_over]
|
| 129 |
-
IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [play]
|
| 130 |
-
|
| 131 |
-
' FOR (auto-declares variable)
|
| 132 |
-
FOR i$ = 1 TO 10 STEP 2 : PRINT i$ : NEXT
|
| 133 |
-
FOR i$ = 10 TO 1 STEP -1 : PRINT i$ : NEXT
|
| 134 |
-
|
| 135 |
-
' WHILE
|
| 136 |
-
WHILE x$ < 100 : x$ = x$ * 2 : WEND
|
| 137 |
-
|
| 138 |
-
' Labels, GOTO, GOSUB
|
| 139 |
-
[start]
|
| 140 |
-
GOSUB [sub:init]
|
| 141 |
-
GOTO [main]
|
| 142 |
-
|
| 143 |
-
[sub:init]
|
| 144 |
-
LET x$ = 0
|
| 145 |
-
RETURN
|
| 146 |
-
|
| 147 |
-
' Dynamic jump (variable must contain "[label]" with brackets)
|
| 148 |
-
LET target$ = "[menu]"
|
| 149 |
-
GOTO target$
|
| 150 |
-
|
| 151 |
-
' Other
|
| 152 |
-
SLEEP 2000 ' Pause ms
|
| 153 |
-
END ' Terminate program
|
| 154 |
-
```
|
| 155 |
-
|
| 156 |
-
---
|
| 157 |
-
|
| 158 |
-
## I/O
|
| 159 |
-
|
| 160 |
-
| Command | Description |
|
| 161 |
-
|---------|-------------|
|
| 162 |
-
| `PRINT expr; expr` | `;` = no space, `,` = tab |
|
| 163 |
-
| `PRINT "text";` | Trailing `;` suppresses newline |
|
| 164 |
-
| `INPUT "prompt", var$` | Splits on whitespace/comma |
|
| 165 |
-
| `INPUT "prompt", a$, b$` | Multiple values |
|
| 166 |
-
| `LINE INPUT "prompt", var$` | Read entire line with spaces |
|
| 167 |
-
| `CLS` | Clear screen |
|
| 168 |
-
| `LOCATE row, col` | Move cursor (1-based) |
|
| 169 |
-
| `CURPOS("row")` / `CURPOS("col")` | Read cursor row or col (1-based, matches LOCATE) |
|
| 170 |
-
| `CURPOS()` | Read cursor as `"row,col"` string |
|
| 171 |
-
| `COLOR fg, bg` | Text colors (0–15 palette) |
|
| 172 |
-
| `SHELL("cmd")` | Run shell command, returns output |
|
| 173 |
-
| `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
|
| 174 |
-
|
| 175 |
-
**Escape sequences in strings:** `\"` `\n` `\t` `\\`
|
| 176 |
-
|
| 177 |
-
### Keyboard Input
|
| 178 |
-
| Function | Returns | Notes |
|
| 179 |
-
|----------|---------|-------|
|
| 180 |
-
| `INKEY` | Key value or 0 | Non-blocking |
|
| 181 |
-
| `KEYDOWN(key#)` | TRUE/FALSE | Held-key detection; **graphics mode only** |
|
| 182 |
-
| `WAITKEY(key#, ...)` | Key value | Blocks until key pressed; `WAITKEY()` = any key |
|
| 183 |
-
|
| 184 |
-
### Mouse (graphics mode only)
|
| 185 |
-
`MOUSEX`, `MOUSEY` — cursor position
|
| 186 |
-
`MOUSELEFT` - `MOUSERIGHT`, `MOUSEMIDDLE` — 1 if pressed, 0 otherwise
|
| 187 |
-
`MOUSEHIDE` — hide the mouse cursor (graphics screen only)
|
| 188 |
-
`MOUSESHOW` — restore the mouse cursor (graphics screen only)
|
| 189 |
-
|
| 190 |
-
### Console Read
|
| 191 |
-
`GETCONSOLE(row, col, type)` — type: 0=char (ASCII), 1=fg color, 2=bg color
|
| 192 |
-
|
| 193 |
-
---
|
| 194 |
-
|
| 195 |
-
## User-Defined Functions
|
| 196 |
-
|
| 197 |
-
```basic
|
| 198 |
-
' Define BEFORE calling. Name must end with $.
|
| 199 |
-
DEF FN Clamp$(val$, lo$, hi$)
|
| 200 |
-
IF val$ < lo$ THEN RETURN lo$
|
| 201 |
-
IF val$ > hi$ THEN RETURN hi$
|
| 202 |
-
RETURN val$
|
| 203 |
-
END DEF
|
| 204 |
-
|
| 205 |
-
PRINT FN Clamp$(5, 1, 10) ' ✓ OK — return value used
|
| 206 |
-
LET v$ = FN Clamp$(15, 0, 10) ' ✓ OK
|
| 207 |
-
FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
| 208 |
-
```
|
| 209 |
-
|
| 210 |
-
- Isolated scope: no access to global variables, only global constants (`#`)
|
| 211 |
-
- Parameters passed **by value**
|
| 212 |
-
- Labels inside functions are local — GOTO/GOSUB cannot jump outside
|
| 213 |
-
- Supports recursion
|
| 214 |
-
- Arrays as parameters not allowed. Use ASJSON to make array as JSON-string to pass it.
|
| 215 |
-
- Use `INCLUDE` to load functions from separate files if many
|
| 216 |
-
|
| 217 |
-
---
|
| 218 |
-
|
| 219 |
-
## String Functions
|
| 220 |
-
|
| 221 |
-
| Function | Description |
|
| 222 |
-
|----------|-------------|
|
| 223 |
-
| `ASC(s$)` | ASCII code of first char |
|
| 224 |
-
| `CHR(n)` | Character from ASCII code |
|
| 225 |
-
| `INSTR(s$, search$)` | Position (1-based), 0=not found; case-sensitive by default |
|
| 226 |
-
| `INSTR(s$, search$, mode)` | mode: 0=case-insensitive, 1=case-sensitive |
|
| 227 |
-
| `INSTR(start, s$, search$)` | Search from position (case-sensitive) |
|
| 228 |
-
| `INVERT(s$)` | Reverse string |
|
| 229 |
-
| `LCASE(s$)` / `UCASE(s$)` | Lower / upper case |
|
| 230 |
-
| `LEFT(s$, n)` / `RIGHT(s$, n)` | First/last n chars |
|
| 231 |
-
| `LEN(s$)` | String length |
|
| 232 |
-
| `LTRIM(s$)` / `RTRIM(s$)` / `TRIM(s$)` | Strip whitespace |
|
| 233 |
-
| `MID(s$, start)` | Substring from start (1-based) |
|
| 234 |
-
| `MID(s$, start, len)` | Substring with length |
|
| 235 |
-
| `REPEAT(s$, n)` | Repeat string n times |
|
| 236 |
-
| `REPLACE(s$, a$, b$)` | Replace a$ with b$ in s$ |
|
| 237 |
-
| `SPLIT(arr$, s$, sep$)` | Split into array, returns count |
|
| 238 |
-
| `SRAND(n)` | Random alphanumeric string of length n |
|
| 239 |
-
| `STR(n)` | Number to string |
|
| 240 |
-
| `VAL(s$)` | String to number |
|
| 241 |
-
| `SHA256(s$)` | SHA256 hash (64-char hex) |
|
| 242 |
-
| `BASE64ENCODE(s$)` / `BASE64DECODE(s$)` | Base64 encode/decode |
|
| 243 |
-
|
| 244 |
-
---
|
| 245 |
-
|
| 246 |
-
## Math Functions
|
| 247 |
-
|
| 248 |
-
| Function | Description |
|
| 249 |
-
|----------|-------------|
|
| 250 |
-
| `ABS(n)` | Absolute value |
|
| 251 |
-
| `ATAN(n)` | Arc tangent |
|
| 252 |
-
| `BETWEEN(n, min, max)` | TRUE if min ≤ n ≤ max |
|
| 253 |
-
| 'INBETWEEN(n, min, max)' |TRUE if min < n < max (strictly between, not equal) |
|
| 254 |
-
| `CEIL(n)` / `FLOOR(n)` | Round up / down |
|
| 255 |
-
| `CINT(n)` | Round to nearest integer |
|
| 256 |
-
| `CLAMP(n, min, max)` | Constrain n to [min, max] |
|
| 257 |
-
| `COS(n)` / `SIN(n)` / `TAN(n)` | Trig (radians) |
|
| 258 |
-
| `DEG(rad)` / `RAD(deg)` | Radians ↔ degrees |
|
| 259 |
-
| `DISTANCE(x1,y1, x2,y2)` | 2D Euclidean distance |
|
| 260 |
-
| `DISTANCE(x1,y1,z1, x2,y2,z2)` | 3D Euclidean distance |
|
| 261 |
-
| `EXP(n)` | e^n |
|
| 262 |
-
| `INT(n)` | Truncate toward zero |
|
| 263 |
-
| `LERP(start, end, t)` | Linear interpolation (t: 0.0–1.0) |
|
| 264 |
-
| `LOG(n)` | Natural logarithm |
|
| 265 |
-
| `MAX(a, b)` / `MIN(a, b)` | Larger / smaller of two |
|
| 266 |
-
| `MOD(a, b)` | Remainder |
|
| 267 |
-
| `POW(base, exp)` | Power |
|
| 268 |
-
| `RND(n)` | Random integer 0 to n-1 |
|
| 269 |
-
| `ROUND(n)` | Standard rounding |
|
| 270 |
-
| `SGN(n)` | Sign: -1, 0, or 1 |
|
| 271 |
-
| `SQR(n)` | Square root |
|
| 272 |
-
|
| 273 |
-
**Math constants:** `PI#`, `HPI#` (PI/2), `QPI#` (PI/4), `TAU#` (PI*2), `EULER#`
|
| 274 |
-
|
| 275 |
-
---
|
| 276 |
-
|
| 277 |
-
## Graphics
|
| 278 |
-
|
| 279 |
-
```basic
|
| 280 |
-
SCREEN 12 ' 640×480 VGA (recommended)
|
| 281 |
-
SCREEN 0, 800, 600 ' Custom size
|
| 282 |
-
SCREEN 0, 1024, 768, "My Game" ' Custom size + title
|
| 283 |
-
FULLSCREEN TRUE ' Borderless fullscreen (graphics only)
|
| 284 |
-
FULLSCREEN FALSE ' Windowed
|
| 285 |
-
```
|
| 286 |
-
|
| 287 |
-
| Mode | Resolution |
|
| 288 |
-
|------|-----------|
|
| 289 |
-
| 1 | 320×200 |
|
| 290 |
-
| 2 | 640×350 |
|
| 291 |
-
| 7 | 320×200 |
|
| 292 |
-
| 9 | 640×350 |
|
| 293 |
-
| 12 | 640×480 ← recommended |
|
| 294 |
-
| 13 | 320×200 |
|
| 295 |
-
|
| 296 |
-
### Drawing Primitives
|
| 297 |
-
```basic
|
| 298 |
-
PSET (x, y), color ' Pixel
|
| 299 |
-
LINE (x1,y1)-(x2,y2), color ' Line
|
| 300 |
-
LINE (x1,y1)-(x2,y2), color, B ' Box outline
|
| 301 |
-
LINE (x1,y1)-(x2,y2), color, BF ' Box filled (FAST — use instead of CLS)
|
| 302 |
-
CIRCLE (cx,cy), radius, color ' Circle outline
|
| 303 |
-
CIRCLE (cx,cy), radius, color, 1 ' Circle filled
|
| 304 |
-
PAINT (x, y), fillColor, borderColor ' Flood fill
|
| 305 |
-
LET c$ = POINT(x, y) ' Read pixel color
|
| 306 |
-
LET col$ = RGB(r, g, b) ' Create color (0–255 each)
|
| 307 |
-
```
|
| 308 |
-
|
| 309 |
-
**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
|
| 310 |
-
|
| 311 |
-
### Screen Control
|
| 312 |
-
```basic
|
| 313 |
-
SCREENLOCK ON ' Buffer drawing (start frame)
|
| 314 |
-
SCREENLOCK OFF ' Present buffer (end frame)
|
| 315 |
-
VSYNC(TRUE) ' Enable VSync (default, ~60 FPS)
|
| 316 |
-
VSYNC(FALSE) ' Disable VSync (benchmarking)
|
| 317 |
-
CLS ' Clear screen (slow — prefer LINE BF)
|
| 318 |
-
```
|
| 319 |
-
|
| 320 |
-
### Shapes & Images
|
| 321 |
-
```basic
|
| 322 |
-
' Create shape
|
| 323 |
-
' LOADSHAPE and LOADIMAGE return a stable integer handle — never reassigned.
|
| 324 |
-
' SDL2 owns the resource; your code only ever holds this one reference. Use constants.
|
| 325 |
-
LET RECT# = LOADSHAPE("RECTANGLE", w, h, color) ' or "CIRCLE", "TRIANGLE"
|
| 326 |
-
LET IMG_PLAYER# = LOADIMAGE("player.png") ' PNG (alpha) or BMP
|
| 327 |
-
LET IMG_REMOTE# = LOADIMAGE("https://example.com/a.png") ' Download + load
|
| 328 |
-
|
| 329 |
-
' Sprite sheet — sprites indexed 1-based
|
| 330 |
-
DIM sprites$
|
| 331 |
-
LOADSHEET sprites$, 128, 128, "sheet.png" ' tileW, tileH, file
|
| 332 |
-
MOVESHAPE sprites$(1), x, y ' sprites$(1) = first sprite
|
| 333 |
-
|
| 334 |
-
' Transform
|
| 335 |
-
MOVESHAPE RECT#, x, y ' Position by center point
|
| 336 |
-
ROTATESHAPE RECT#, angle ' Degrees (absolute)
|
| 337 |
-
SCALESHAPE RECT#, scale ' 1.0 = original size
|
| 338 |
-
DRAWSHAPE RECT# ' Render to buffer
|
| 339 |
-
SHOWSHAPE RECT# / HIDESHAPE RECT# ' Toggle visibility
|
| 340 |
-
REMOVESHAPE RECT# ' Free memory (always clean up)
|
| 341 |
-
```
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
---
|
| 345 |
-
|
| 346 |
-
### Text Rendering (SDL2_ttf.dll required)
|
| 347 |
-
#### DRAWSTRING & LOADFONT
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
```basic
|
| 351 |
-
' Default font (Arial)
|
| 352 |
-
DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
|
| 353 |
-
|
| 354 |
-
' Load alternative font — becomes the new default
|
| 355 |
-
LOADFONT "comic.ttf", 24
|
| 356 |
-
DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
|
| 357 |
-
|
| 358 |
-
' Reset to Arial
|
| 359 |
-
LOADFONT
|
| 360 |
-
```
|
| 361 |
-
|
| 362 |
-
`DRAWSTRING x, y` positions the top-left of the text. Requires `SDL2_ttf.dll` in the same directory as the interpreter. Prefer this over PRINT, which makes graphic screen easily blinking.
|
| 363 |
-
|
| 364 |
-
---
|
| 365 |
-
|
| 366 |
-
## Sound
|
| 367 |
-
|
| 368 |
-
```basic
|
| 369 |
-
' LOADSOUND returns a stable integer handle — SDL2 manages the resource.
|
| 370 |
-
' The handle never changes; store it in a constant to protect it from accidental reassignment.
|
| 371 |
-
LET SND_JUMP# = LOADSOUND("jump.wav") ' Load (WAV recommended)
|
| 372 |
-
SOUNDONCE(SND_JUMP#) ' Play once, non-blocking
|
| 373 |
-
SOUNDONCEWAIT(SND_JUMP#) ' Play once, wait for finish
|
| 374 |
-
SOUNDREPEAT(SND_JUMP#) ' Loop continuously
|
| 375 |
-
SOUNDSTOP(SND_JUMP#) ' Stop specific sound
|
| 376 |
-
SOUNDSTOPALL ' Stop all sounds
|
| 377 |
-
```
|
| 378 |
-
|
| 379 |
-
Load all sounds at startup. Call `SOUNDSTOPALL` before `END`.
|
| 380 |
-
|
| 381 |
-
---
|
| 382 |
-
|
| 383 |
-
## File I/O
|
| 384 |
-
|
| 385 |
-
```basic
|
| 386 |
-
LET data$ = FileRead("file.txt") ' Read as string
|
| 387 |
-
DIM cfg$ : LET cfg$ = FileRead("settings.txt") ' Read as key=value array
|
| 388 |
-
FileWrite "save.txt", data$ ' Create/overwrite
|
| 389 |
-
FileAppend "log.txt", entry$ ' Append
|
| 390 |
-
LET ok$ = FileExists("file.txt") ' 1=exists, 0=not
|
| 391 |
-
FileDelete "temp.dat" ' Delete file
|
| 392 |
-
```
|
| 393 |
-
|
| 394 |
-
**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.
|
| 395 |
-
|
| 396 |
-
```basic
|
| 397 |
-
DIM env$
|
| 398 |
-
LET env$ = FileRead(".env")
|
| 399 |
-
LET API_KEY# = env$("OPENAI_API_KEY")
|
| 400 |
-
```
|
| 401 |
-
|
| 402 |
-
**Paths:** Use `/` or `\\` — never single `\` (it's an escape char). Relative paths are from `PRG_ROOT#`.
|
| 403 |
-
**FileWrite with array** saves in key=value format (round-trips with FileRead).
|
| 404 |
-
|
| 405 |
-
---
|
| 406 |
-
|
| 407 |
-
## Network
|
| 408 |
-
|
| 409 |
-
```basic
|
| 410 |
-
LET res$ = HTTPGET("https://api.example.com/data")
|
| 411 |
-
LET res$ = HTTPPOST("https://api.example.com/submit", "{""key"":""val""}")
|
| 412 |
-
|
| 413 |
-
' With headers (optional last parameter)
|
| 414 |
-
DIM headers$
|
| 415 |
-
headers$("Authorization") = "Bearer mytoken"
|
| 416 |
-
headers$("Content-Type") = "application/json"
|
| 417 |
-
LET res$ = HTTPGET("https://api.example.com/data", headers$)
|
| 418 |
-
LET res$ = HTTPPOST("https://api.example.com/data", body$, headers$)
|
| 419 |
-
```
|
| 420 |
-
|
| 421 |
-
---
|
| 422 |
-
|
| 423 |
-
## Arrays & JSON
|
| 424 |
-
|
| 425 |
-
Nested JSON maps to comma-separated keys: `data$("player,name")`, `data$("skills,0")`
|
| 426 |
-
|
| 427 |
-
```basic
|
| 428 |
-
' Array → JSON string
|
| 429 |
-
LET json$ = ASJSON(arr$)
|
| 430 |
-
|
| 431 |
-
' JSON string → array (returns element count)
|
| 432 |
-
DIM data$
|
| 433 |
-
LET count$ = ASARRAY(data$, json$)
|
| 434 |
-
|
| 435 |
-
' Load/save JSON files
|
| 436 |
-
LOADJSON arr$, "file.json"
|
| 437 |
-
SAVEJSON arr$, "file.json"
|
| 438 |
-
```
|
| 439 |
-
|
| 440 |
-
---
|
| 441 |
-
|
| 442 |
-
## Fast Trigonometry
|
| 443 |
-
|
| 444 |
-
~20× faster than `SIN(RAD(x))`, 1-degree precision. Uses ~5.6 KB memory.
|
| 445 |
-
|
| 446 |
-
```basic
|
| 447 |
-
FastTrig(TRUE) ' Enable lookup tables (must call first)
|
| 448 |
-
LET x$ = FastCos(45) ' Degrees, auto-normalized 0–359
|
| 449 |
-
LET y$ = FastSin(90)
|
| 450 |
-
LET r$ = FastRad(180) ' Deg→rad (no FastTrig needed)
|
| 451 |
-
FastTrig(FALSE) ' Free memory
|
| 452 |
-
```
|
| 453 |
-
|
| 454 |
-
Use for raycasting, sprite rotation, particle systems, any high-freq trig.
|
| 455 |
-
|
| 456 |
-
---
|
| 457 |
-
|
| 458 |
-
## Command-Line Arguments
|
| 459 |
-
|
| 460 |
-
```basic
|
| 461 |
-
' bazzbasic.exe myprog.bas arg1 arg2
|
| 462 |
-
PRINT ARGCOUNT ' number of args (2 in this example)
|
| 463 |
-
PRINT ARGS(0) ' first arg → "arg1"
|
| 464 |
-
PRINT ARGS(1) ' second arg → "arg2"
|
| 465 |
-
```
|
| 466 |
-
|
| 467 |
-
`ARGCOUNT` and `ARGS(n)` are 0-based; ARGS does not include the interpreter or script name.
|
| 468 |
-
|
| 469 |
-
---
|
| 470 |
-
|
| 471 |
-
## Libraries & INCLUDE
|
| 472 |
-
|
| 473 |
-
```basic
|
| 474 |
-
INCLUDE "helpers.bas" ' Insert source at this point
|
| 475 |
-
INCLUDE "MathLib.bb" ' Load compiled library
|
| 476 |
-
|
| 477 |
-
' Compile library (functions only — no loose code)
|
| 478 |
-
' bazzbasic.exe -lib MathLib.bas → MathLib.bb
|
| 479 |
-
' Function names auto-prefixed: MATHLIB_functionname$
|
| 480 |
-
PRINT FN MATHLIB_add$(5, 3)
|
| 481 |
-
```
|
| 482 |
-
|
| 483 |
-
Library functions can read main-program constants (`#`). `.bb` files are version-locked.
|
| 484 |
-
|
| 485 |
-
---
|
| 486 |
-
|
| 487 |
-
## Passing Arrays to Functions
|
| 488 |
-
|
| 489 |
-
Arrays cannot be passed directly to `DEF FN` functions, but a clean workaround exists using JSON serialization. Convert the array to a JSON string with `ASJSON`, pass the string as a parameter, then deserialize inside the function with `ASARRAY`. This is the accepted pattern in BazzBasic v1.2+.
|
| 490 |
-
|
| 491 |
-
```basic
|
| 492 |
-
DEF FN ProcessPlayer$(data$)
|
| 493 |
-
DIM arr$
|
| 494 |
-
LET count$ = ASARRAY(arr$, data$)
|
| 495 |
-
RETURN arr$("name") + " score:" + arr$("score")
|
| 496 |
-
END DEF
|
| 497 |
-
|
| 498 |
-
[inits]
|
| 499 |
-
DIM player$
|
| 500 |
-
player$("name") = "Alice"
|
| 501 |
-
player$("score") = 9999
|
| 502 |
-
player$("address,city") = "New York"
|
| 503 |
-
|
| 504 |
-
[main]
|
| 505 |
-
LET json$ = ASJSON(player$)
|
| 506 |
-
PRINT FN ProcessPlayer$(json$)
|
| 507 |
-
END
|
| 508 |
-
```
|
| 509 |
-
|
| 510 |
-
**Notes:**
|
| 511 |
-
- The function receives a full independent copy — changes inside do not affect the original array
|
| 512 |
-
- Nested keys work normally: `arr$("address,city")` etc.
|
| 513 |
-
- Overhead is similar to copying an array manually; acceptable for most use cases
|
| 514 |
-
|
| 515 |
-
---
|
| 516 |
-
|
| 517 |
-
## Program Structure
|
| 518 |
-
|
| 519 |
-
```basic
|
| 520 |
-
' ---- 1. FUNCTIONS (or INCLUDE "functions.bas") ----
|
| 521 |
-
DEF FN Clamp$(v$, lo$, hi$)
|
| 522 |
-
IF v$ < lo$ THEN RETURN lo$
|
| 523 |
-
IF v$ > hi$ THEN RETURN hi$
|
| 524 |
-
RETURN v$
|
| 525 |
-
END DEF
|
| 526 |
-
|
| 527 |
-
' ---- 2. INIT (declare ALL constants & variables here, not inside loops) ----
|
| 528 |
-
' Performance: variables declared outside loops avoid repeated existence checks.
|
| 529 |
-
[inits]
|
| 530 |
-
LET SCREEN_W# = 640
|
| 531 |
-
LET SCREEN_H# = 480
|
| 532 |
-
LET MAX_SPEED# = 5
|
| 533 |
-
|
| 534 |
-
SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
|
| 535 |
-
|
| 536 |
-
LET x$ = 320
|
| 537 |
-
LET y$ = 240
|
| 538 |
-
LET running$ = TRUE
|
| 539 |
-
|
| 540 |
-
' ---- 3. MAIN LOOP ----
|
| 541 |
-
[main]
|
| 542 |
-
WHILE running$
|
| 543 |
-
IF INKEY = KEY_ESC# THEN running$ = FALSE
|
| 544 |
-
GOSUB [sub:update]
|
| 545 |
-
GOSUB [sub:draw]
|
| 546 |
-
SLEEP 16
|
| 547 |
-
WEND
|
| 548 |
-
SOUNDSTOPALL
|
| 549 |
-
END
|
| 550 |
-
|
| 551 |
-
' ---- 4. SUBROUTINES (or INCLUDE "subs.bas") ----
|
| 552 |
-
[sub:update]
|
| 553 |
-
IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED#
|
| 554 |
-
IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED#
|
| 555 |
-
RETURN
|
| 556 |
-
|
| 557 |
-
[sub:draw]
|
| 558 |
-
SCREENLOCK ON
|
| 559 |
-
LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
|
| 560 |
-
CIRCLE (x$, y$), 10, RGB(0, 255, 0), 1
|
| 561 |
-
SCREENLOCK OFF
|
| 562 |
-
RETURN
|
| 563 |
-
```
|
| 564 |
-
|
| 565 |
-
**Key conventions:**
|
| 566 |
-
- Variables: `camelCase$` | Constants: `UPPER_SNAKE_CASE#` | Functions: `PascalCase$`
|
| 567 |
-
- Labels: `[gameLoop]` for jump targets, `[sub:name]` for subroutines
|
| 568 |
-
- Image/sound/shape IDs are stable integer handles — **always** store as constants: `LET MY_IMG# = LOADIMAGE("x.png")` — never use `$` variables for these
|
| 569 |
-
- Group many IDs → use arrays: `DIM sprites$` / `sprites$("player") = LOADIMAGE(...)` — but prefer named constants when count is small
|
| 570 |
-
|
| 571 |
-
---
|
| 572 |
-
|
| 573 |
-
## Performance Tips
|
| 574 |
-
|
| 575 |
-
- `LINE (0,0)-(W,H), 0, BF` to clear — much faster than `CLS`
|
| 576 |
-
- Always wrap draw code in `SCREENLOCK ON` / `SCREENLOCK OFF`
|
| 577 |
-
- Store `RGB()` results in constants/variables — don't call RGB in hot loops
|
| 578 |
-
- Declare all variables in `[inits]`, not inside loops or subroutines
|
| 579 |
-
- Use `FastTrig` for any loop calling trig hundreds of times per frame
|
| 580 |
-
- `SLEEP 16` in game loop → ~60 FPS
|
| 581 |
-
|
| 582 |
-
---
|
| 583 |
-
|
| 584 |
-
## IDE Features (v1.3)
|
| 585 |
-
|
| 586 |
-
### New File Template
|
| 587 |
-
When the IDE opens with no file (or a new file), this template is auto-inserted:
|
| 588 |
-
```basic
|
| 589 |
-
' BazzBasic version 1.3
|
| 590 |
-
' https://ekbass.github.io/BazzBasic/
|
| 591 |
-
```
|
| 592 |
-
|
| 593 |
-
### Beginner's Guide
|
| 594 |
-
- **IDE:** Menu → **Help** → **Beginner's Guide** — opens `https://github.com/EkBass/BazzBasic-Beginners-Guide/releases` in default browser
|
| 595 |
-
- **CLI:** `bazzbasic.exe -guide` or `bazzbasic.exe -help` — prints URL to terminal
|
| 596 |
-
|
| 597 |
-
### Check for Updates
|
| 598 |
-
- **IDE:** Menu → **Help** → **Check for updated...** — IDE reports if a newer version is available
|
| 599 |
-
- **CLI:** `bazzbasic.exe -checkupdate`
|
| 600 |
-
|
| 601 |
-
### Compile via IDE
|
| 602 |
-
- **Menu → Run → Compile as Exe** — compiles open file to standalone `.exe` (auto-saves first)
|
| 603 |
-
- **Menu → Run → Compile as Library (.bb)** — compiles open file as reusable `.bb` library (auto-saves first)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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