EkBass commited on
Commit
61199b6
·
verified ·
1 Parent(s): 0b51466

Upload BazzBasic-AI-guide-01-05-2026.txt

Browse files

Updated to BazzBasic version 1.4 released 01.05.2026

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