EkBass commited on
Commit
1b1d1d7
·
verified ·
1 Parent(s): 9862633

Upload BazzBasic-AI-guide-07052026.txt

Browse files
Files changed (1) hide show
  1. BazzBasic-AI-guide-07052026.txt +1054 -0
BazzBasic-AI-guide-07052026.txt ADDED
@@ -0,0 +1,1054 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ doc. date: 06.05.2026 (dd.mm.yyyy)
6
+
7
+ filename: BazzBasic-AI-guide-ddmmyyyyX.txt (ddmmyyyy = date of last update) (X is small alphabet "abcd..." presenting daily version incase two versions are released in same day)
8
+
9
+ IE:
10
+ BazzBasic-AI-Guide30042026.txt ' version released 30th April 2026
11
+ BazzBasic-AI-Guide30042026b.txt ' version released 30th April 2026, second in same date
12
+ ---
13
+
14
+ # BazzBasic Language Reference
15
+ **Version:** 1.4 | **Author:** Kristian Virtanen (EkBass) | **Platform:** Windows x64
16
+ **Homepage:** https://ekbass.github.io/BazzBasic/
17
+ **GitHub:** https://github.com/EkBass/BazzBasic
18
+ **Manual:** https://ekbass.github.io/BazzBasic/manual/#/
19
+ **Examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples
20
+ **Rosetta Code:** https://rosettacode.org/wiki/Category:BazzBasic
21
+ **Rosetta Code solutions:** https://github.com/EkBass/BazzBasic/tree/main/Examples/rosetta-code
22
+ **BazzBasic-AI-Guide:** https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
23
+ **BazzBasic Beginner's Guide:** https://github.com/EkBass/BazzBasic-Beginners-Guide/releases
24
+ **Communities:** https://ekbass.github.io/BazzBasic/communities.html
25
+
26
+ ---
27
+
28
+ ## Critical Rules Read First
29
+
30
+ | Rule | Detail |
31
+ |------|--------|
32
+ | Variables end with `$` | `name$`, `score$`, `x$` |
33
+ | Constants end with `#` | `MAX#`, `PI#`, `TITLE#` |
34
+ | Arrays declared with `DIM`, end with `$` | `DIM items$` |
35
+ | First use of variable requires `LET` | `LET x$ = 0` after that `x$ = x$ + 1` |
36
+ | FOR and INPUT auto-declare, no LET needed | `FOR i$ = 1 TO 10` |
37
+ | Functions defined **before** they are called | Put at top or INCLUDE |
38
+ | Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
39
+ | Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
40
+ | Arrays **cannot** be passed to functions directly | Pass individual elements, or serialize to JSON string see *Passing Arrays to Functions* section |
41
+ | Case-insensitive | `PRINT`, `print`, `Print` all work |
42
+ | `+` operator does both add and concatenate | `"Hi" + " " + name$` |
43
+ | Division always returns float | `10 / 3` → `3.333...` |
44
+ | Division by zero returns `0` (no error) | Guard with `IF b$ = 0 THEN ...` if needed |
45
+ | No integer-division operator | Use `INT(a / b)`, `FLOOR(a / b)`, or `CINT(a / b)` |
46
+ | Errors halt the program | No `TRY`/`CATCH` or `ON ERROR` line-numbered message printed |
47
+ | Declare variables inside of [inits] at begin of code. Not inside [sub:xxx], since it slows BazzBasic |
48
+
49
+ ---
50
+
51
+ ## Common AI Mistakes (avoid these)
52
+
53
+ These are the patterns LLMs most often produce when extrapolating from QBASIC, FreeBASIC, or VB. None of them are valid BazzBasic.
54
+
55
+ ```basic
56
+ ' WRONG ' CORRECT
57
+ LET x = 5 LET x$ = 5
58
+ LET MAX = 10 LET MAX# = 10
59
+ score$ = 0 ' first use LET score$ = 0
60
+ DEF FN doStuff(a, b) DEF FN DoStuff$(a$, b$)
61
+ FN MyFunc$(5) ' return ignored LET v$ = FN MyFunc$(5)
62
+ LET handle$ = LOADIMAGE("x.png") LET HANDLE# = LOADIMAGE("x.png")
63
+ CLS ' in graphics mode LINE (0,0)-(W,H), 0, BF
64
+ PRINT "x:", x$ ' in graphics mode DRAWSTRING "x:" + STR(x$), 10, 10, RGB(255,255,255)
65
+ FSTRING("Hi {{name$}}") ' Python-style FSTRING("Hi {{-name$-}}") ' triple-char markers
66
+ ISSET(arr$(0)) ' expecting error ' returns 0 silently ISSET only sees scalars
67
+ LET x$ = a$ + _ ' VBA continuation LET x$ = a$ + ' just leave the operator
68
+ LET x$ = a$ + \ ' Python continuation LET x$ = a$ + ' or open a paren see Line Continuation
69
+ ```
70
+
71
+ **Two more traps that don't fit the table:**
72
+
73
+ - Inside `DEF FN` you can read `#` constants from the outer scope but **not** `$` variables. Pass them as parameters.
74
+ - Arrays cannot be passed to a function. Serialize with `ASJSON()` and rebuild inside the function with `ASARRAY()` see *Passing Arrays to Functions* below.
75
+
76
+ ---
77
+
78
+ ## Minimal Valid Program
79
+
80
+ ```basic
81
+ ' User-defined functions first
82
+
83
+ [inits]
84
+ ' constants
85
+ LET MY_CONST# = 123
86
+
87
+ ' variables
88
+ LET name$ = "World"
89
+ LET foo$ ' declare also variables even they are assigned later to speed up the process
90
+
91
+ [main]
92
+ foo$ = 123
93
+ PRINT "Hello, " + name$
94
+ PRINT foo$
95
+ END
96
+ ```
97
+
98
+ Programs flow top to bottom. `[inits]` and `[main]` are organizational labels, not required syntax the file would also run without them. `END` halts execution; place it at the end of the main flow so control doesn't fall through into subroutines or function definitions.
99
+
100
+ ---
101
+
102
+ ## When Generating BazzBasic Code
103
+
104
+ - Always declare variables with `LET` on first use; subsequent uses don't need it
105
+ - Always include the `$` (variable) or `#` (constant) suffix
106
+ - Place `DEF FN` definitions at the top of the file or via `INCLUDE`
107
+ - Store every `LOADIMAGE` / `LOADSOUND` / `LOADSHAPE` handle as a `#` constant
108
+ - In graphics mode, prefer `LINE (0,0)-(W,H), 0, BF` over `CLS`, and `DRAWSTRING` over `PRINT`
109
+ - Wrap each frame's drawing in `SCREENLOCK ON` / `SCREENLOCK OFF`
110
+ - Always use a function's return value assign with `LET` or consume with `PRINT` or `IF`
111
+ - If a feature isn't documented in this guide, say so rather than inventing one BazzBasic does not silently inherit QBASIC, FreeBASIC, or VB conventions
112
+ - Declare variables at start, inside of [inits] when ever possible. Inside of [sub:xxx] 'LET' just wastes time since BazzBasic has to check if variable is declared already.
113
+
114
+ ---
115
+
116
+
117
+ ## ABOUT
118
+ 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.
119
+
120
+ ### What people have built with it
121
+
122
+ BazzBasic is built for beginners, but it isn't a toy. It can carry real 2D games and even 2.5D graphics work.
123
+
124
+ - https://github.com/EkBass/BazzBasic/blob/main/Examples/Voxel_terrain.bas
125
+ A Comanche-style heightmap renderer with procedurally generated terrain. Eight smoothing passes turn random noise into hills, valleys, water, beaches, forests, rock, and snow each assigned a color by height band.
126
+ - https://github.com/EkBass/BazzBasic/blob/main/Examples/Raycaster_3d_optimized.bas
127
+ A smooth first-person raycaster engine written entirely in BazzBasic. Minimap, depth shading and real-time movement proves that BazzBasic can handle serious graphics work.
128
+ - https://ek-bass.itch.io/rgb-vision
129
+ A speedrun platformer made for Jam for All BASIC Dialects #7 (itch.io).
130
+ - https://github.com/EkBass/BazzBasic/blob/main/Examples/2D_maze_FOV_demo_console.bas
131
+ 2D maze with FOV in your console
132
+ - https://ek-bass.itch.io/eliza-bazzbasic-edition
133
+ A classic DOCTOR script from the 60s which made people honestly believe they are talking to a real human. Grandmother of modern AIs.
134
+ - https://github.com/EkBass/BazzBasic/blob/main/Examples/rosetta-code/BrainFuck.bas
135
+ BrainFuck interpreter. One of the first programs ever done with BazzBasic.
136
+ - https://github.com/EkBass/BazzBasic/blob/main/Examples/Anthropic_Claude_API_call.bas & https://github.com/EkBass/BazzBasic/blob/main/Examples/OpenAI_request.bas
137
+ Anthropic Claude API and OpenAI ChatGPT API available, both with less than 50 lines of code.
138
+
139
+ **Note:** All ".../Examples/..." codes are delivered with BazzBasic and they are found on the BazzBasic executable folder.
140
+
141
+ ### STORY
142
+ 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. 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. BazzBasic was created with this in mind. I wanted to create a language that makes it easy for you to give free rein to your curiosity and program something. And when you finish your first little game, you may crave something bigger and better. Maybe one day you will move on to another programming language, but then BazzBasic will have succeeded in doing what it was intended for.
143
+ To arouse your curiosity.
144
+ *EkBass*, author of BazzBasic
145
+
146
+ ---
147
+
148
+ ## Case sensitivity
149
+ BazzBasic is not case-sensitive except with string contents.
150
+ ```basic
151
+ let blaa$ = "Hello"
152
+ PriNT BLAA$ ' output: Hello
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Line Continuation
158
+
159
+ BazzBasic has **no line-continuation character**. Do not generate `_` (VBA), `\` (Python), or `&` (other dialects). The lexer figures out continuation automatically using two rules.
160
+
161
+ **Rule 1 operator at end of line.** If a line ends in a token that cannot legally end an expression, the next line continues it:
162
+
163
+ ```basic
164
+ LET total$ = price$ * count$ -
165
+ discount$
166
+
167
+ IF score$ >= 0 AND
168
+ score$ <= 100 THEN
169
+ PRINT "Valid"
170
+ END IF
171
+
172
+ LET counter$ +=
173
+ step$
174
+ ```
175
+
176
+ Tokens that trigger this: `+ - * / % = <> < <= > >= AND OR += -= *= /= ,`
177
+
178
+ > `MOD` is a function `MOD(a, b)`, not a binary operator it does not trigger continuation. Use `%` for the modulo operator.
179
+
180
+ **Rule 2 open paren.** Anything inside an unmatched `(` keeps reading until the matching `)`:
181
+
182
+ ```basic
183
+ LET dist$ = DISTANCE(
184
+ x1$, y1$,
185
+ x2$, y2$
186
+ )
187
+ ```
188
+
189
+ Both rules combine:
190
+
191
+ ```basic
192
+ LET total$ = (
193
+ base$ +
194
+ tax$
195
+ )
196
+ ```
197
+
198
+ **Trap for AI generators.** Do NOT emit a trailing `_`, `\`, `&`, or any other continuation marker they are not BazzBasic syntax and will produce parse errors. Just leave the operator at the end of the line, or open a paren.
199
+
200
+ ---
201
+
202
+ ## Variables & Constants
203
+ Variables and constants must be declared with LET before they can be used.
204
+ BazzBasic variables are not typed, but work the same way as in JavaScript, for example.
205
+ A variable needs the suffix $ which often is linked as STRING in traditional basic variants.
206
+
207
+ Variables require suffix "$". Constants require suffix "#".
208
+ The suffix does not define data type only "#" indicates immutability.
209
+ ```basic
210
+ LET a$ ' Declare variable without value
211
+ LET b$, c$, d$ ' Multiple variable declarations without value
212
+ LET e$, f$ = "foo", g$ = 10 ' Multiple variable declaration, e$ stays empty, f$ and g$ gets values
213
+
214
+ LET name$ = "Alice" ' String variable
215
+ LET score$ = 0 ' Numeric variable
216
+
217
+ LET PI# = 3.14159 ' Constant (immutable)
218
+ LET TITLE# = "My Game" ' String constant
219
+ ```
220
+
221
+ **Compound assignment operators** (variables only **not** allowed with `#` constants):
222
+
223
+ ```basic
224
+ LET x$ = 1
225
+ x$ += 5 ' add
226
+ x$ -= 3 ' subtract
227
+ x$ *= 2 ' multiply
228
+ x$ /= 4 ' divide
229
+ LET s$ = "Hello"
230
+ s$ += " World" ' string concatenation
231
+ ```
232
+
233
+ **Scope:** All main-code variables share one scope (IF, FOR, and WHILE do NOT create new scope).
234
+ Main-code variables ($) are NOT accessible inside DEF FN
235
+ `DEF FN` functions are fully isolated only global constants (`#`) accessible inside.
236
+
237
+ **Comparison:** `"123" = 123` is TRUE (cross-type), but keep types consistent for speed.
238
+
239
+ ---
240
+
241
+ ### Built-in Constants
242
+ - **Boolean:** `TRUE`, `FALSE` ' These two does not require suffix '#'
243
+ - **Math:** `PI#`, `HPI#` (PI#/2), `QPI#` (PI#/4), `TAU#` (PI# * 2), `EULER#` (e) `#` suffix required
244
+ - **System:** `PRG_ROOT#` (program base directory path)
245
+ - **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.
246
+
247
+ ---
248
+
249
+ ## Arrays
250
+ BazzBasic arrays are fully dynamic and support numeric, string, or mixed indexing.
251
+
252
+
253
+ ```basic
254
+ DIM scores$ ' Declare (required before use)
255
+ DIM a$, b$, c$ ' Multiple
256
+ scores$(0) = 95 ' Numeric indices are 0-based.
257
+ scores$("name") = "Alice" ' String keys are associative and unordered.
258
+ matrix$(0, 1) = "A2" ' Multi-dimensional
259
+
260
+ DIM sounds$
261
+ sounds$("guns", "shotgun_shoot") = "shoot_shotgun.wav"
262
+ sounds$("guns", "shotgun_reload") = "reload_shotgun.wav"
263
+ sounds$("guns", "ak47_shoot") = "shoot_ak47.wav"
264
+ sounds$("guns", "ak47_reload") = "reload_ak47.wav"
265
+ sounds$("food", "ham_eat") = "eat_ham.wav"
266
+
267
+ PRINT LEN(sounds$()) ' 5 as full size of arrayas there is total of 5 values in array
268
+ PRINT ROWCOUNT(sounds$()) ' 2, "guns" & "food"
269
+ ```
270
+
271
+ | Function/Command | Description |
272
+ |-----------------|-------------|
273
+ | `LEN(arr$())` | Total element count (LEN counts all nested elements across all dimensions) |
274
+ | `ROWCOUNT(arr$())` | Count of first-dimension rows use this for FOR loops over multi-dim arrays |
275
+ | `HASKEY(arr$(key))` | 1 if exists, 0 if not |
276
+ | `DELKEY arr$(key)` | Remove one element |
277
+ | `DELARRAY arr$` | Remove entire array (can re-DIM after) |
278
+ | `JOIN dest$, src1$, src2$` | Merge two arrays; `src2$` keys overwrite `src1$`. Use empty `src1$` as `COPYARRAY`. |
279
+
280
+ **JOIN** Matching keys from src2$ overwrite src1$ at the same level
281
+
282
+ **Always check with `HASKEY` before reading uninitialized elements.**
283
+
284
+ ---
285
+
286
+ ## Control Flow
287
+
288
+ ```basic
289
+ ' Block IF
290
+ IF score$ >= 90 THEN
291
+ PRINT "A"
292
+ ELSEIF score$ >= 80 THEN
293
+ PRINT "B"
294
+ ELSE
295
+ PRINT "F"
296
+ END IF ' ENDIF also works
297
+
298
+ ' One-line IF
299
+ IF lives$ = 0 THEN GOTO [game_over]
300
+ IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [play]
301
+
302
+ ' FOR (auto-declares variable)
303
+ FOR i$ = 1 TO 10 STEP 2 : PRINT i$ : NEXT
304
+ FOR i$ = 10 TO 1 STEP -1 : PRINT i$ : NEXT
305
+
306
+ ' WHILE
307
+ WHILE x$ < 100
308
+ x$ = x$ * 2
309
+ WEND
310
+
311
+ ' Labels, GOTO, GOSUB
312
+ [start]
313
+ GOSUB [sub:init]
314
+ ' Avoid jumping into the middle of logical blocks (e.g. inside IF/WHILE)
315
+ GOTO [start]
316
+
317
+ [sub:init]
318
+ LET x$ = 0
319
+ RETURN
320
+
321
+ ' Dynamic jump (variable must contain "[label]" with brackets)
322
+ LET target$ = "[menu]"
323
+ GOTO target$
324
+
325
+ ' Other
326
+ SLEEP 2000 ' Pause for milliseconds
327
+ END ' Terminate program
328
+ ```
329
+ **Note:** Labels are case-insensitive and may contain almost any printable character.
330
+ Whitespace is trimmed. Everything between "[" and "]" is treated as the label name.
331
+ ---
332
+
333
+ ## I/O
334
+
335
+ | Command | Description |
336
+ |---------|-------------|
337
+ | `PRINT expr; expr` | `;` = no space, `,` = tab |
338
+ | `PRINT "text";` | Trailing `;` suppresses newline |
339
+ | `INPUT "prompt", var$` | Splits on whitespace/comma |
340
+ | `INPUT "prompt", a$, b$` | Multiple values |
341
+ | `LINE INPUT "prompt", var$` | Read entire line with spaces |
342
+ | `CLS` | Clear screen |
343
+ | `LOCATE row, col` | Move cursor (1-based) |
344
+ | `CURPOS("row")` / `CURPOS("col")` | Read cursor row or col (1-based, matches LOCATE) |
345
+ | `CURPOS()` | Read cursor as `"row,col"` string |
346
+ | `COLOR fg, bg` | Text colors (0-15 palette) |
347
+ | `SHELL("cmd")` | Run shell command, returns output |
348
+ | `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
349
+
350
+ ' ; prints without spacing
351
+ ' , prints tab separation
352
+ ' Both can be mixed in a single PRINT statement
353
+ ' INPUT splits on whitespace and comma; quoted strings are treated as single values
354
+
355
+ **Escape sequences in strings:** `\"` `\n` `\t` `\\`
356
+
357
+ **SHELL + SQLite.** SQLite (the `sqlite3` CLI tool) is the recommended way to add a real database to a BazzBasic script — see the *SQLite Database* page in the manual for the full guide. Three things to remember when generating SHELL commands that wrap SQL:
358
+ - Always append `2>&1` to the command, or SQL errors disappear silently.
359
+ - Use `\"` (BazzBasic escape) to wrap the SQL for the OS shell: `SHELL("sqlite3 db.sqlite \"SELECT * FROM users\" 2>&1")`.
360
+ - In paths use `/` or `\\` — never a single `\`.
361
+
362
+ ### Keyboard Input
363
+ | Function | Returns | Notes |
364
+ |----------|---------|-------|
365
+ | `INKEY` | Key value or 0 | Non-blocking |
366
+ | `KEYDOWN(key#)` | TRUE/FALSE | Held-key detection; KEYDOWN only works in graphics mode |
367
+ | `WAITKEY(key#, ...)` | Key value | Blocks until key pressed; `WAITKEY()` = any key |
368
+
369
+ ### Mouse (graphics mode only)
370
+ `MOUSEX`, `MOUSEY` cursor position
371
+ `MOUSELEFT`, MOUSERIGHT, MOUSEMIDDLE return 1 if pressed, 0 otherwise
372
+ `MOUSEHIDE` hide the mouse cursor (graphics screen only)
373
+ `MOUSESHOW` restore the mouse cursor (graphics screen only)
374
+
375
+ ### Console Read
376
+ Returns numeric or character depending on type parameter
377
+ `GETCONSOLE(row, col, type)` type: 0=char (ASCII), 1=fg color, 2=bg color
378
+
379
+ ---
380
+
381
+ ## User-Defined Functions
382
+
383
+ ```basic
384
+ ' Define BEFORE calling. Name must end with $.
385
+ DEF FN Clamp$(val$, lo$, hi$)
386
+ IF val$ < lo$ THEN RETURN lo$
387
+ IF val$ > hi$ THEN RETURN hi$
388
+ RETURN val$
389
+ END DEF
390
+
391
+ PRINT FN Clamp$(5, 1, 10) ' OK return value used
392
+ LET v$ = FN Clamp$(15, 0, 10) ' OK
393
+ FN Clamp$(5, 1, 10) ' ERROR return value unused
394
+ ' Return value must be assigned with LET or consumed by PRINT there is no way to silently discard it.
395
+ ```
396
+
397
+ - Isolated scope: no access to global variables, only global constants (`#`)
398
+ - Parameters passed **by value**
399
+ - Labels inside functions are local GOTO/GOSUB cannot jump outside
400
+ - Supports recursion
401
+ - Arrays as parameters not allowed. Use ASJSON to make array as JSON-string to pass it.
402
+ - Use `INCLUDE` to load functions from separate files if many
403
+
404
+ ---
405
+
406
+ ## String Functions
407
+
408
+ | Function | Description |
409
+ |----------|-------------|
410
+ | `ASC(s$)` | ASCII code of first char |
411
+ | `CHR(n)` | Character from ASCII code |
412
+ | `FSTRING(template$)` | String interpolation with `{{-name-}}` placeholders. See dedicated FSTRING section below for full syntax. |
413
+ | `INSTR(s$, search$)` | Position (1-based), 0=not found; case-sensitive by default |
414
+ | `INSTR(s$, search$, mode)` | mode: 0=case-insensitive, 1=case-sensitive |
415
+ | `INSTR(start, s$, search$)` | Search from position (case-sensitive) |
416
+ | `INVERT(s$)` | Reverse string |
417
+ | `LCASE(s$)` / `UCASE(s$)` | Lower / upper case |
418
+ | `LEFT(s$, n)` / `RIGHT(s$, n)` | First/last n chars |
419
+ | `LEN(s$)` | String length |
420
+ | `LTRIM(s$)` / `RTRIM(s$)` / `TRIM(s$)` | Strip whitespace |
421
+ | `MID(s$, start)` | Substring from start (1-based) |
422
+ | `MID(s$, start, len)` | Substring with length |
423
+ | `REPEAT(s$, n)` | Repeat string n times |
424
+ | `REPLACE(s$, a$, b$)` | Replace a$ with b$ in s$ |
425
+ | `SPLIT(arr$, s$, sep$)` | Split into array, returns count. Expects array is declared with DIM |
426
+ | `SRAND(n)` | Random alphanumeric string of length n |
427
+ | `STR(n)` | Number to string |
428
+ | `VAL(s$)` | String to number |
429
+ | `SHA256(s$)` | SHA256 hash (64-char hex) |
430
+ | `BASE64ENCODE(s$)` / `BASE64DECODE(s$)` | Base64 encode/decode |
431
+
432
+ ---
433
+
434
+ ## FSTRING - String Interpolation
435
+
436
+ `FSTRING(template$)` substitutes `{{-name-}}` placeholders inside a template
437
+ string with the value of variables, constants, or array elements. It is the
438
+ recommended alternative to long `+` concatenation chains.
439
+
440
+ ```basic
441
+ LET name$ = "Krisu"
442
+ LET LEVEL# = 5
443
+ PRINT FSTRING("Hello {{-name$-}}, level {{-LEVEL#-}}")
444
+ ' Output: Hello Krisu, level 5
445
+ ```
446
+
447
+ ### Why the `{{-...-}}` markers?
448
+
449
+ The triple-character markers `{{-` and `-}}` are deliberately unusual so they
450
+ will not collide with normal text inside a string. There is no escape syntax;
451
+ if a template contains literal `{{-...-}}`, FSTRING will always try to resolve
452
+ it as a placeholder.
453
+
454
+ ### Placeholder forms
455
+
456
+ | Form | Resolves to |
457
+ |------|-------------|
458
+ | `{{-var$-}}` | Value of variable `var$` |
459
+ | `{{-CONST#-}}` | Value of constant `CONST#` |
460
+ | `{{-arr$(0)-}}` | Array element at numeric index `0` |
461
+ | `{{-arr$(i$)-}}` | Array element at index taken from variable `i$` |
462
+ | `{{-arr$(KEY#)-}}` | Array element at index taken from constant `KEY#` |
463
+ | `{{-arr$(name)-}}` | Array element at literal string key `"name"` (no quotes inside FSTRING) |
464
+ | `{{-arr$(0, i$)-}}` | Multidimensional element, mixed literal and variable indices |
465
+
466
+ ### Index resolution rule (for array access)
467
+
468
+ For each comma-separated index, FSTRING decides what it is by looking at the
469
+ last character:
470
+
471
+ 1. Ends with `$` or `#` -> treat as variable / constant lookup. Halts with an
472
+ error if the name is not defined.
473
+ 2. Parses as a number (`0`, `1.5`, `-3`) -> treat as a numeric index. The
474
+ number is normalised through a double round-trip so `arr$(01)` and
475
+ `arr$(1.0)` both find the key `1`.
476
+ 3. Otherwise -> treat as a literal string key. This is what lets you write
477
+ `{{-player$(name)-}}` to read what was stored with `player$("name") = ...`.
478
+
479
+ ### Whitespace inside placeholders
480
+
481
+ All whitespace inside a placeholder is trimmed, so these are equivalent:
482
+
483
+ ```basic
484
+ FSTRING("{{-name$-}}")
485
+ FSTRING("{{- name$ -}}")
486
+ FSTRING("{{- name$ -}}")
487
+ FSTRING("{{- arr$( 0 , i$ ) -}}")
488
+ ```
489
+
490
+ ### Numbers auto-stringify
491
+
492
+ Both numeric variables / constants and array elements that hold numbers are
493
+ converted to strings automatically (no `STR()` needed):
494
+
495
+ ```basic
496
+ LET score$ = 42
497
+ LET pi# = 3.14159
498
+ PRINT FSTRING("Score: {{-score$-}}, Pi: {{-pi#-}}")
499
+ ' Output: Score: 42, Pi: 3.14159
500
+ ```
501
+
502
+ ### What is NOT supported (intentional)
503
+
504
+ These are out of scope; FSTRING is meant to stay simple and predictable. Use
505
+ a normal variable to pre-compute, then reference that variable in FSTRING.
506
+
507
+ ```basic
508
+ ' WRONG: arithmetic inside placeholder
509
+ PRINT FSTRING("Total: {{-a$ + 5-}}")
510
+
511
+ ' WRONG: function call inside placeholder
512
+ PRINT FSTRING("Name: {{-UCASE(name$)-}}")
513
+
514
+ ' WRONG: nested array lookup inside placeholder
515
+ PRINT FSTRING("{{-arr$(arr2$(0))-}}")
516
+
517
+ ' WRONG: string literal with quotes inside placeholder
518
+ PRINT FSTRING("{{-arr$(\"name\")-}}")
519
+ ```
520
+
521
+ ```basic
522
+ ' RIGHT: pre-compute, then reference
523
+ LET total$ = a$ + 5
524
+ LET upper$ = UCASE(name$)
525
+ LET k$ = arr2$(0)
526
+ PRINT FSTRING("Total: {{-total$-}}, Name: {{-upper$-}}, Item: {{-arr$(k$)-}}")
527
+ ```
528
+
529
+ ### Errors halt execution
530
+
531
+ Like other BazzBasic errors, these print a line-numbered message and stop
532
+ the program:
533
+
534
+ - `FSTRING: undefined variable 'foo$'.`
535
+ - `FSTRING: undefined variable 'i$' in array index of 'arr$(i$)'.`
536
+ - `FSTRING: missing closing '-}}' in template.`
537
+ - `FSTRING: empty placeholder '{{--}}'.`
538
+ - `FSTRING: malformed array access '...'.`
539
+ - `FSTRING: Array element ...(...) not initialized` (the standard array error,
540
+ prefixed with FSTRING).
541
+
542
+ ### Common AI mistakes with FSTRING
543
+
544
+ ```basic
545
+ ' WRONG: forgot the dashes
546
+ LET s$ = FSTRING("Hi {{name$}}")
547
+
548
+ ' WRONG: only one brace pair
549
+ LET s$ = FSTRING("Hi {-name$-}")
550
+
551
+ ' WRONG: $ suffix omitted in placeholder
552
+ LET s$ = FSTRING("Hi {{-name-}}")
553
+ ' This compiles but treats `name` as a literal key for an array lookup.
554
+ ' If `name` is intended as a variable, write `{{-name$-}}`.
555
+
556
+ ' WRONG: using FSTRING as a statement
557
+ FSTRING("Hi {{-name$-}}")
558
+ ' FSTRING returns a value; you must use it: LET / PRINT / pass to function.
559
+
560
+ ' RIGHT
561
+ LET s$ = FSTRING("Hi {{-name$-}}, level {{-LEVEL#-}}")
562
+ PRINT FSTRING("Score: {{-score$-}}")
563
+ ```
564
+
565
+ ### Full working example
566
+
567
+ ```basic
568
+ DIM player$
569
+ player$("name") = "Krisu"
570
+ player$("class") = "Bass"
571
+ player$("level") = 99
572
+
573
+ DIM grid$
574
+ grid$(0, 0) = "X"
575
+ grid$(0, 1) = "O"
576
+ grid$(1, 0) = "."
577
+ grid$(1, 1) = "X"
578
+
579
+ LET row$ = 1
580
+ LET PI# = 3.14
581
+
582
+ PRINT FSTRING("{{-player$(name)-}} the {{-player$(class)-}}, lvl {{-player$(level)-}}")
583
+ PRINT FSTRING("Row {{-row$-}}: [{{-grid$(row$, 0)-}}{{-grid$(row$, 1)-}}]")
584
+ PRINT FSTRING("Pi is roughly {{-PI#-}}")
585
+ END
586
+ ```
587
+
588
+ Output:
589
+ ```
590
+ Krisu the Bass, lvl 99
591
+ Row 1: [.X]
592
+ Pi is roughly 3.14
593
+ ```
594
+
595
+ ---
596
+
597
+ ## Math Functions
598
+
599
+ | Function | Description |
600
+ |----------|-------------|
601
+ | `ABS(n)` | Absolute value |
602
+ | `ATAN(n)` | Arc tangent |
603
+ | `ATAN2(x, y)` | Returns the angle, in radians, between the positive x-axis and a vector to the point with the given (x, y) coordinates in the Cartesian plane |
604
+ | `BETWEEN(n, min, max)` | TRUE if min ≤ n ≤ max |
605
+ | `INBETWEEN(n, min, max)` | TRUE if min < n < max (strictly between, not equal) |
606
+ | `CEIL(n)` / `FLOOR(n)` | Round up / down |
607
+ | `CINT(n)` | Round to nearest integer |
608
+ | `CLAMP(n, min, max)` | Constrain n to [min, max] |
609
+ | `COS(n)` / `SIN(n)` / `TAN(n)` | Trig (radians) |
610
+ | `DEG(rad)` / `RAD(deg)` | Radians ↔ degrees |
611
+ | `DISTANCE(x1,y1, x2,y2)` | 2D Euclidean distance |
612
+ | `DISTANCE(x1,y1,z1, x2,y2,z2)` | 3D Euclidean distance |
613
+ | `EXP(n)` | e^n |
614
+ | `INT(n)` | Truncate toward zero |
615
+ | `LERP(start, end, t)` | Linear interpolation (t: 0.0–1.0) |
616
+ | `LOG(n)` | Natural logarithm |
617
+ | `MAX(a, b)` / `MIN(a, b)` | Larger / smaller of two |
618
+ | `MOD(a, b)` | Remainder |
619
+ | `POW(base, exp)` | Power |
620
+ | `RND(n)` | Random integer 0 to n-1 if n > 0 |
621
+ | `RND(0)` | Float between 0.0 and 1.0 (IE: 0.5841907423666761) |
622
+ | `ROUND(n)` | Standard rounding |
623
+ | `SGN(n)` | Sign: -1, 0, or 1 |
624
+ | `SQR(n)` | Square root |
625
+
626
+ **Math constants:** `PI#`, `HPI#` (PI/2), `QPI#` (PI/4), `TAU#` (PI*2), `EULER#`
627
+
628
+ ---
629
+
630
+ ## Variable Functions
631
+
632
+ | Function | Description |
633
+ |----------|-------------|
634
+ | `ISSET(name)` | `1` if the named variable (`$`) or constant (`#`) is declared, `0` otherwise. Argument is **not evaluated** `ISSET(undef$)` safely returns `0`. |
635
+
636
+ `ISSET` is the only language-introspection function and it has tight rules:
637
+
638
+ - **Scalars only.** Variables (`$`) and constants (`#`). Arrays and array
639
+ elements are stored separately `ISSET(arr$)` and `ISSET(arr$(0))` always
640
+ return `0`, never an error.
641
+ - **Bare name only.** No expressions, no string literals, no numbers. These
642
+ all error with "invalid parameter":
643
+ ```basic
644
+ ISSET(a$ + b$) ' WRONG: expression
645
+ ISSET("a$") ' WRONG: string literal
646
+ ISSET(42) ' WRONG: number
647
+ ISSET() ' WRONG: empty
648
+ ```
649
+ - **Suffix is part of the name.** `a$` and `A#` are different names:
650
+ ```basic
651
+ LET a$ = "foo"
652
+ PRINT ISSET(a$) ' 1
653
+ PRINT ISSET(A#) ' 0
654
+ ```
655
+ - **`LET name$` (no value) still counts as set.** `LET` always registers the
656
+ variable; the value just defaults to empty string for `$` and zero for
657
+ numeric. `ISSET` reports declaration, not "has a meaningful value".
658
+
659
+ Typical use is guarding optional setup:
660
+
661
+ ```basic
662
+ IF NOT ISSET(playerName$) THEN
663
+ LET playerName$ = "Anonymous"
664
+ END IF
665
+ ```
666
+
667
+ ---
668
+
669
+ ## Graphics
670
+
671
+ ```basic
672
+ SCREEN 12 ' 640×480 VGA
673
+ SCREEN 0, 800, 600 ' Custom size
674
+ SCREEN 0, 1024, 768, "My Game" ' Custom size + title
675
+ FULLSCREEN TRUE ' Borderless fullscreen (graphics only)
676
+ FULLSCREEN FALSE ' Windowed
677
+ ```
678
+
679
+ | Mode | Resolution |
680
+ |------|-----------|
681
+ | 1 | 320×200 |
682
+ | 2 | 640×350 |
683
+ | 7 | 320×200 |
684
+ | 9 | 640×350 |
685
+ | 12 | 640×480 ← recommended |
686
+ | 13 | 320×200 |
687
+
688
+ ### Drawing Primitives
689
+ ```basic
690
+ PSET (x, y), color ' Pixel
691
+ LINE (x1,y1)-(x2,y2), color ' Line
692
+ LINE (x1,y1)-(x2,y2), color, B ' Box outline
693
+ LINE (x1,y1)-(x2,y2), color, BF ' Box filled (FAST use instead of CLS)
694
+ CIRCLE (cx,cy), radius, color ' Circle outline
695
+ CIRCLE (cx,cy), radius, color, 1 ' Circle filled
696
+ PAINT (x, y), fillColor, borderColor ' Flood fill
697
+ LET c$ = POINT(x, y) ' Read pixel color
698
+ LET col$ = RGB(r, g, b) ' Create color (0–255 each)
699
+ ```
700
+
701
+ **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
702
+
703
+ ### Screen Control
704
+ ```basic
705
+ SCREENLOCK ON ' Buffer drawing (start frame)
706
+ SCREENLOCK OFF ' Present buffer (end frame)
707
+ VSYNC(TRUE) ' Enable VSync (default, ~60 FPS)
708
+ VSYNC(FALSE) ' Disable VSync (benchmarking)
709
+ CLS ' Clear screen
710
+ ' Use CLS only with console, in graphics screen its slow
711
+ ' With graphics screen, prefer LINE BF
712
+ ```
713
+
714
+ ### Shapes & Images
715
+ ```basic
716
+ ' Create shape
717
+ ' LOADSHAPE and LOADIMAGE return a stable integer handle never reassigned.
718
+ ' SDL2 owns the resource; your code only ever holds this one reference. Use constants.
719
+ LET RECT# = LOADSHAPE("RECTANGLE", w, h, color) ' or "CIRCLE", "TRIANGLE"
720
+ LET IMG_PLAYER# = LOADIMAGE("player.png") ' PNG (alpha) or BMP
721
+ LET IMG_REMOTE# = LOADIMAGE("https://example.com/a.png") ' Download + load
722
+
723
+ ' Sprite sheet sprites indexed 1-based
724
+ DIM sprites$
725
+ LOADSHEET sprites$, 128, 128, "sheet.png" ' tileW, tileH, file
726
+ MOVESHAPE sprites$(1), x, y ' sprites$(1) = first sprite
727
+
728
+ ' Transform
729
+ MOVESHAPE RECT#, x, y ' Position by top-left
730
+ ROTATESHAPE RECT#, angle ' Degrees (absolute)
731
+ SCALESHAPE RECT#, scale ' 1.0 = original size
732
+ DRAWSHAPE RECT# ' Render to buffer
733
+ SHOWSHAPE RECT# / HIDESHAPE RECT# ' Toggle visibility
734
+ REMOVESHAPE RECT# ' Free memory (always clean up)
735
+ ```
736
+
737
+
738
+ ---
739
+
740
+ ### Text Rendering (SDL2_ttf.dll required)
741
+ #### DRAWSTRING & LOADFONT
742
+
743
+
744
+ ```basic
745
+ ' Default font (Arial)
746
+ DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
747
+
748
+ ' Load alternative font becomes the new default
749
+ LOADFONT "comic.ttf", 24
750
+ DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
751
+
752
+ ' Reset to Arial
753
+ LOADFONT
754
+ ```
755
+
756
+ `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.
757
+
758
+ ---
759
+
760
+ ## Sound
761
+
762
+ ```basic
763
+ ' LOADSOUND returns a stable integer handle SDL2 manages the resource.
764
+ ' The handle never changes; store it in a constant to protect it from accidental reassignment.
765
+ LET SND_JUMP# = LOADSOUND("jump.wav") ' Load (WAV recommended)
766
+ SOUNDONCE(SND_JUMP#) ' Play once, non-blocking
767
+ SOUNDONCEWAIT(SND_JUMP#) ' Play once, wait for finish
768
+ SOUNDREPEAT(SND_JUMP#) ' Loop continuously
769
+ SOUNDSTOP(SND_JUMP#) ' Stop specific sound
770
+ SOUNDSTOPALL ' Stop all sounds
771
+ ```
772
+
773
+ Load all sounds at startup. Call `SOUNDSTOPALL` before `END`.
774
+
775
+ ---
776
+
777
+ ## File I/O
778
+
779
+ ```basic
780
+ LET data$ = FILEREAD("file.txt") ' Read as string
781
+ DIM cfg$ : LET cfg$ = FILEREAD("settings.txt") ' Read as key=value array
782
+ FILEWRITE "save.txt", data$ ' Create/overwrite
783
+ FILEAPPEND "log.txt", entry$ ' Append
784
+ LET ok$ = FILEEXISTS("file.txt") ' 1=exists, 0=not
785
+ FILEDELETE "temp.dat" ' Delete file
786
+ ```
787
+
788
+ **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.
789
+
790
+ ```basic
791
+ DIM env$
792
+ LET env$ = FILEREAD(".env")
793
+ LET API_KEY# = env$("OPENAI_API_KEY")
794
+ ```
795
+
796
+ **Paths:** Use `/` or `\\` never single `\` (it's an escape char). Relative paths are from `PRG_ROOT#`.
797
+ **FILEWRITE with array** saves in key=value format (round-trips with FILEREAD).
798
+
799
+ ---
800
+
801
+ ## Network
802
+
803
+ ```basic
804
+ LET res$ = HTTPGET("https://api.example.com/data")
805
+ LET res$ = HTTPPOST("https://api.example.com/submit", "{""key"":""val""}")
806
+
807
+ ' With headers (optional last parameter)
808
+ DIM headers$
809
+ headers$("Authorization") = "Bearer mytoken"
810
+ headers$("Content-Type") = "application/json"
811
+ LET res$ = HTTPGET("https://api.example.com/data", headers$)
812
+ LET res$ = HTTPPOST("https://api.example.com/data", body$, headers$)
813
+ ```
814
+
815
+ ### Local HTTP server (LISTEN)
816
+
817
+ BazzBasic can also receive requests as a local-only HTTP server, typically used as glue between a static HTML page and a BazzBasic script on the same machine.
818
+
819
+ ```basic
820
+ STARTLISTEN 8080 ' bind 127.0.0.1:8080, no admin needed
821
+ STARTLISTEN 8080, 5000 ' optional timeout in ms
822
+ LET body$ = GETREQUEST() ' POST/PUT/PATCH body, or GET query string ("" on timeout)
823
+ SENDRESPONSE "{""status"":""ok""}" ' must be called or browser hangs
824
+ STOPLISTEN
825
+ ```
826
+
827
+ Important rules:
828
+
829
+ - **Always pair `GETREQUEST()` with `SENDRESPONSE`.** The browser is waiting on the response. Forgetting `SENDRESPONSE` makes the page hang.
830
+ - **Bound to `127.0.0.1` only.** This is local glue, not a real web server. Do not generate code that tries to expose this on the LAN or internet.
831
+ - **Body or query string, not full request.** `GETREQUEST()` returns just the POST body (or the GET query string without `?`). Headers, method, and URL path are NOT exposed in this version. If you need structured data, parse the body with `ASARRAY(body$)`.
832
+ - **OPTIONS preflight is automatic.** Do NOT write code that handles `OPTIONS` it is consumed silently and never reaches user code.
833
+ - **CORS is automatic.** Every response carries `Access-Control-Allow-Origin: *`. No need to set it manually.
834
+ - **One listener at a time.** Calling `STARTLISTEN` while one is already active is an error. Call `STOPLISTEN` first.
835
+ - **Always 200 OK, always `text/plain`.** Custom status codes and content types are not supported in this version. To return JSON, just put JSON text in the body browser-side `response.json()` still works.
836
+
837
+ Typical receive-and-process pattern:
838
+
839
+ ```basic
840
+ STARTLISTEN 8080
841
+ PRINT "Waiting for browser..."
842
+
843
+ LET json$ = GETREQUEST()
844
+ DIM data$
845
+ LET data$ = ASARRAY(json$)
846
+
847
+ PRINT "Got name: " + data$("name")
848
+
849
+ SENDRESPONSE "{""status"":""ok""}"
850
+ STOPLISTEN
851
+ END
852
+ ```
853
+
854
+ ---
855
+
856
+ ## Arrays & JSON
857
+
858
+ Nested JSON maps to comma-separated keys: `data$("player,name")`, `data$("skills,0")`
859
+
860
+ ```basic
861
+ ' Array → JSON string
862
+ LET json$ = ASJSON(arr$)
863
+
864
+ ' JSON string → array (returns element count)
865
+ DIM data$
866
+ LET count$ = ASARRAY(data$, json$)
867
+
868
+ ' Load/save JSON files
869
+ LOADJSON arr$, "file.json"
870
+ SAVEJSON arr$, "file.json"
871
+ ```
872
+
873
+ ---
874
+
875
+ ## Fast Trigonometry
876
+
877
+ ~20× faster than `SIN(RAD(x))`, 1-degree (integer) precision. Uses ~5.6 KB memory.
878
+
879
+ ```basic
880
+ FastTrig(TRUE) ' Enable lookup tables (must call first)
881
+ LET x$ = FastCos(45) ' Degrees, auto-normalized 0–359
882
+ LET y$ = FastSin(90)
883
+ LET r$ = FastRad(180) ' Deg→rad (no FastTrig needed)
884
+ FastTrig(FALSE) ' Free memory
885
+ ```
886
+
887
+ Use for raycasting, sprite rotation, particle systems, any high-freq trig.
888
+
889
+ ---
890
+
891
+ ## Command-Line Arguments
892
+
893
+ ```basic
894
+ ' bazzbasic.exe myprog.bas arg1 arg2
895
+ PRINT ARGCOUNT ' number of args (2 in this example)
896
+ PRINT ARGS(0) ' first arg → "arg1"
897
+ PRINT ARGS(1) ' second arg → "arg2"
898
+ ```
899
+
900
+ `ARGCOUNT` and `ARGS(n)` are 0-based; ARGS does not include the interpreter or script name.
901
+
902
+ ---
903
+
904
+ ## Libraries & INCLUDE
905
+
906
+ ```basic
907
+ INCLUDE "helpers.bas" ' Insert source at this point
908
+ INCLUDE "MathLib.bb" ' Load compiled library
909
+
910
+ ' Compile library (functions only no loose code)
911
+ ' bazzbasic.exe -lib MathLib.bas → MathLib.bb
912
+ ' Function names auto-prefixed: MATHLIB_functionname$
913
+ PRINT FN MATHLIB_add$(5, 3)
914
+ ```
915
+
916
+ Library functions can read main-program constants (`#`). `.bb` files are version-locked.
917
+
918
+ ---
919
+
920
+ ## Passing Arrays to Functions
921
+
922
+ 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+.
923
+
924
+ ```basic
925
+ DEF FN ProcessPlayer$(data$)
926
+ DIM arr$
927
+ LET count$ = ASARRAY(arr$, data$)
928
+ RETURN arr$("name") + " score:" + arr$("score")
929
+ END DEF
930
+
931
+ [inits]
932
+ DIM player$
933
+ player$("name") = "Alice"
934
+ player$("score") = 9999
935
+ player$("address,city") = "New York"
936
+
937
+ [main]
938
+ LET json$ = ASJSON(player$)
939
+ PRINT FN ProcessPlayer$(json$)
940
+ END
941
+ ```
942
+
943
+ **Notes:**
944
+ - The function receives a full independent copy changes inside do not affect the original array
945
+ - Nested keys work normally: `arr$("address,city")` etc.
946
+ - Overhead is similar to copying an array manually; acceptable for most use cases
947
+
948
+ ---
949
+
950
+ ## Program Structure
951
+
952
+ ```basic
953
+ ' ---- 1. FUNCTIONS (or INCLUDE "functions.bas/bb") ----
954
+ DEF FN Clamp$(v$, lo$, hi$)
955
+ IF v$ < lo$ THEN RETURN lo$
956
+ IF v$ > hi$ THEN RETURN hi$
957
+ RETURN v$
958
+ END DEF
959
+
960
+ ' ---- 2. INIT (declare ALL constants & variables here, not inside loops) ----
961
+ ' Performance: variables declared outside loops avoid repeated existence checks.
962
+ [inits]
963
+ LET SCREEN_W# = 640
964
+ LET SCREEN_H# = 480
965
+ LET MAX_SPEED# = 5
966
+
967
+ SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
968
+
969
+ LET x$ = 320
970
+ LET y$ = 240
971
+ LET running$ = TRUE
972
+
973
+ ' ---- 3. MAIN LOOP ----
974
+ [main]
975
+ WHILE running$
976
+ IF INKEY = KEY_ESC# THEN running$ = FALSE
977
+ GOSUB [sub:update]
978
+ GOSUB [sub:draw]
979
+ SLEEP 16
980
+ WEND
981
+ SOUNDSTOPALL
982
+ END ' place at the end of main program so BazzBasic wont fall to subs in runtime
983
+
984
+ ' ---- 4. SUBROUTINES (or INCLUDE "subs.bas") ----
985
+ [sub:update]
986
+ IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED#
987
+ IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED#
988
+ RETURN
989
+
990
+ [sub:draw]
991
+ SCREENLOCK ON
992
+ LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
993
+ CIRCLE (x$, y$), 10, RGB(0, 255, 0), 1
994
+ SCREENLOCK OFF
995
+ RETURN
996
+ ```
997
+
998
+ **Key conventions:**
999
+ - Variables: `camelCase$` | Constants: `UPPER_SNAKE_CASE#` | Functions: `PascalCase$`
1000
+ - Labels: `[gameLoop]` for jump targets, `[sub:name]` for subroutines
1001
+ - Image/sound/shape IDs are stable integer handles **always** store as constants: `LET MY_IMG# = LOADIMAGE("x.png")` never use `$` variables for these
1002
+ - Group many IDs → use arrays: `DIM sprites$` / `sprites$("player") = LOADIMAGE(...)` but prefer named constants when count is small
1003
+
1004
+ ---
1005
+
1006
+ ## Performance Tips
1007
+
1008
+ - `LINE (0,0)-(W,H), 0, BF` to clear much faster than `CLS`
1009
+ - Always wrap draw code in `SCREENLOCK ON` / `SCREENLOCK OFF`
1010
+ - Store `RGB()` results in constants/variables don't call RGB in hot loops
1011
+ - Declare all variables in `[inits]`, not inside loops or subroutines
1012
+ - Use `FastTrig` for any loop calling trig hundreds of times per frame
1013
+ - `SLEEP 16` in game loop → ~60 FPS
1014
+
1015
+ ---
1016
+
1017
+ ## Known Limitations
1018
+
1019
+ Things to be aware of most are deliberate design decisions, a few are practical constraints.
1020
+
1021
+ - **Platform: Windows x64 only.** Linux and macOS are not supported. Browser/Android are not feasible the runtime depends on SDL2 via P/Invoke.
1022
+ - **Arrays cannot be passed to functions.** Use the `ASJSON` / `ASARRAY` round-trip pattern. The function receives an independent copy.
1023
+ - **`DEF FN` scope is fully isolated.** Functions can read global `#` constants but cannot see any `$` variables from the outer scope. Pass values as parameters.
1024
+ - **No block scope.** `IF`, `FOR`, and `WHILE` do not create new variable scopes all main-code variables share one namespace.
1025
+ - **No exception handling.** There is no `TRY`/`CATCH` and no `ON ERROR`. Runtime errors halt the program with a line-numbered message printed to the console.
1026
+ - **Division by zero returns `0` silently.** No exception, no warning. Guard with `IF b$ = 0 THEN ...` when correctness matters.
1027
+ - **No integer-division operator.** Use `INT(a / b)`, `FLOOR(a / b)`, or `CINT(a / b)` depending on the rounding behavior you need.
1028
+ - **Compiled `.bb` libraries are version-locked** to the BazzBasic build that produced them. Recompile after upgrading the interpreter.
1029
+ - **`DEF FN` definitions must precede their first call** in source order. Forward references don't resolve.
1030
+
1031
+ ---
1032
+
1033
+ ## IDE Features (v1.4)
1034
+
1035
+ ### New File Template
1036
+ When the IDE opens with no file (or a new file), this template is auto-inserted:
1037
+ ```basic
1038
+ ' BazzBasic version {ver_num}
1039
+ ' https://ekbass.github.io/BazzBasic/
1040
+ ```
1041
+
1042
+ ### Beginner's Guide
1043
+ - **IDE:** Menu → **Help** → **Beginner's Guide** opens `https://github.com/EkBass/BazzBasic-Beginners-Guide/releases` in default browser
1044
+ - **CLI:** `bazzbasic.exe -guide` or `bazzbasic.exe -help` prints URL to terminal
1045
+
1046
+ ### Check for Updates
1047
+ - **IDE:** Menu → **Help** → **Check for updated...** IDE reports if a newer version is available
1048
+ - **CLI:** `bazzbasic.exe -checkupdate`
1049
+
1050
+ ### Compile via IDE
1051
+ - **Menu → Run → Compile as Exe** compiles open file to standalone `.exe` (auto-saves first)
1052
+ - **Menu → Run → Compile as Library (.bb)** compiles open file as reusable `.bb` library (auto-saves first)
1053
+
1054
+ EOF