EkBass commited on
Commit
9e6f738
·
verified ·
1 Parent(s): 106f493

Upload BazzBasic-AI-guide-21032026.md

Browse files
Files changed (1) hide show
  1. BazzBasic-AI-guide-21032026.md +985 -0
BazzBasic-AI-guide-21032026.md ADDED
@@ -0,0 +1,985 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ > METADATA:
2
+ > Name: BazzBasic
3
+
4
+ > Description: BazzBasic BASIC interpreter language reference. Use when writing, debugging, or explaining BazzBasic code (.bas files). Triggers on BazzBasic syntax, BASIC programming with $ and # suffixes, SDL2 graphics in BASIC, or references to BazzBasic interpreter features
5
+
6
+ > About: BazzBasic is built around one simple idea: starting programming should feel nice and even fun. Ease of learning, comfort of exploration and small but important moments of success. Just like the classic BASICs of decades past, but with a fresh and modern feel.
7
+
8
+ > Purpose: This guide has been provided with the idea that it would be easy and efficient for a modern AI to use this guide and through this either guide a new programmer to the secrets of BazzBasic or, if necessary, generate code himself.
9
+
10
+ > Version: This guide is written for BazzBasic version 1.0 and is updated 19.03.2026 09:51 Finnish time.
11
+
12
+ ---
13
+
14
+ # BazzBasic Language Reference
15
+
16
+ BazzBasic is a BASIC interpreter for .NET 10 with SDL2 graphics and SDL2_mixer sound support. It is not a clone of any previous BASIC — it aims to be easy, fun, and modern. Released under MIT license.
17
+
18
+ **Version:** 1.0 (Released February 22, 2026)
19
+ **Author:** Kristian Virtanen (krisu.virtanen@gmail.com)
20
+ **Platform:** Windows (x64 primary); Linux/macOS possible with effort
21
+ **Dependencies:** SDL2.dll, SDL2_mixer (bundled).
22
+ **Github:** https://github.com/EkBass/BazzBasic
23
+ **Homepage:** https://ekbass.github.io/BazzBasic/
24
+ **Manual:** "https://ekbass.github.io/BazzBasic/manual/#/"
25
+ **Examples:** "https://github.com/EkBass/BazzBasic/tree/main/Examples"
26
+ **Github_repo:** "https://github.com/EkBass/BazzBasic"
27
+ **Github_discussions:** "https://github.com/EkBass/BazzBasic/discussions"
28
+ **Discord_channel:** "https://discord.com/channels/682603735515529216/1464283741919907932"
29
+ **Thinbasic subforum:** "https://www.thinbasic.com/community/forumdisplay.php?401-BazzBasic"
30
+
31
+ ## Few examples:
32
+ **raycaster_3d:** https://raw.githubusercontent.com/EkBass/BazzBasic/refs/heads/main/Examples/raycaster_3d_optimized.bas
33
+ **voxel_terrain:** https://raw.githubusercontent.com/EkBass/BazzBasic/refs/heads/main/Examples/voxel_terrain.bas
34
+ **sprite load:** https://github.com/EkBass/BazzBasic/blob/main/Examples/countdown_demo.bas
35
+ **Eliza:** https://github.com/EkBass/BazzBasic/blob/main/Examples/Eliza.bas
36
+
37
+ ## This guide:
38
+ **BazzBasic AI-guide:** https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide/tree/main
39
+ Just download the latest *BazzBasic-AI-guide-DDMMYYYY.md* where *DDMMYYYY* marks the date.
40
+
41
+
42
+ ## CLI Usage
43
+
44
+ | Command | Action |
45
+ |---------|--------|
46
+ | `bazzbasic.exe` | Launch IDE |
47
+ | `bazzbasic.exe file.bas` | Run program |
48
+ | `bazzbasic.exe -exe file.bas` | Create standalone .exe |
49
+ | `bazzbasic.exe -lib file.bas` | Create tokenized library (.bb) |
50
+
51
+ IDE shortcuts: F5 run, Ctrl+N/O/S new/open/save, Ctrl+Shift+S save as, Ctrl+W close tab, Ctrl+F find, Ctrl+H replace.
52
+
53
+ In-built IDE is just a small very basic IDE which fires up when double-clicking *bazzbasic.exe*. Usage of Notepad++ etc. recommended.
54
+
55
+ ### External syntax colors.
56
+ BazzBasic IDE is developed just so double-clicking *bazzbasic.exe* would bring something in the screen of a newbie. A person can use it, but it stands no chance for more advanced editors.
57
+
58
+ There are syntax color files for *Notepad++*, *Geany* and *Visual Studio Code* available at https://github.com/EkBass/BazzBasic/tree/main/extras
59
+
60
+ ---
61
+
62
+ ## Syntax Fundamentals
63
+
64
+ ### Variables and Constants
65
+ Forget traditional BASIC types. Suffixes in BazzBasic define mutability, not data type.
66
+
67
+ Variables and arrays in BazzBasic are typeless: hold numbers or strings interchangeably
68
+
69
+ - $ = Mutable Variable
70
+ - # = Immutable Constant
71
+
72
+
73
+ ```basic
74
+ LET a$ ' Declare without value
75
+ LET name$ = "Alice" ' Variable, string (mutable, $ suffix)
76
+ LET age$ = 19 ' Variable, integer (mutable, $ suffix)
77
+ LET price$ = 1.99 ' Variable, decimal (mutable, $ suffix)
78
+ LET PI# = 3.14159 ' Constant (immutable, # suffix)
79
+ LET x$, y$, z$ = 10 ' Multiple declaration
80
+ ```
81
+ - All variables require `$` suffix, constants require `#`
82
+ - Typeless: hold numbers or strings interchangeably
83
+ - Must declare with `LET` before use (except FOR/INPUT which auto-declare)
84
+ - Assignment after declaration: `x$ = x$ + 1` (no LET needed)
85
+ - **Case-insensitive**: `PRINT`, `print`, `Print` all work
86
+ - Naming: letters, numbers, underscores; cannot start with number
87
+
88
+ ### Comparison Behavior
89
+ `"123" = 123` is TRUE (cross-type comparison), but slower — keep types consistent.
90
+
91
+ ### Scope
92
+ - Main code shares one scope (even inside IF blocks)
93
+ - `DEF FN` functions have completely isolated scope
94
+ - Only global constants (`#`) are accessible inside functions
95
+
96
+ ### Multiple Statements Per Line
97
+ ```basic
98
+ COLOR 14, 0 : CLS : PRINT "Hello"
99
+ ```
100
+
101
+ ### Comments
102
+ ```basic
103
+ REM This is a comment
104
+ ' This is also a comment
105
+ PRINT "Hello" ' Inline comment
106
+ ```
107
+
108
+ ### Escape Sequences in Strings
109
+ | Sequence | Result |
110
+ |----------|--------|
111
+ | `\"` | Quote |
112
+ | `\n` | Newline |
113
+ | `\t` | Tab |
114
+ | `\\` | Backslash |
115
+
116
+ ---
117
+
118
+ ## Arrays
119
+ ```basic
120
+ DIM scores$ ' Declare (must use DIM)
121
+ DIM a$, b$, c$ ' Multiple declaration
122
+ scores$(0) = 95 ' Numeric index (0-based)
123
+ scores$("name") = "Alice" ' String key (associative)
124
+ matrix$(0, 1) = "A2" ' Multi-dimensional
125
+ data$(1, "header") = "Name" ' Mixed indexing
126
+ ```
127
+ - Array names must end with `$`
128
+ - Fully dynamic: numeric, string, multi-dimensional, mixed indexing
129
+ - Arrays **cannot** be passed directly to functions — pass values of individual elements
130
+ - Accessing uninitialized elements is an error — check with `HASKEY` first
131
+
132
+ ### Array Functions
133
+ | Function | Description |
134
+ |----------|-------------|
135
+ | `LEN(arr$())` | Element count (note: empty parens) |
136
+ | `HASKEY(arr$(key))` | 1 if exists, 0 if not |
137
+ | `DELKEY arr$(key)` | Remove element |
138
+ | `DELARRAY arr$` | Remove entire array (can re-DIM after) |
139
+
140
+ ---
141
+
142
+ ## Operators
143
+
144
+ ### Arithmetic
145
+ `+` (add/concatenate), `-`, `*`, `/` (returns float)
146
+
147
+ ### Comparison
148
+ `=` or `==`, `<>` or `!=`, `<`, `>`, `<=`, `>=`
149
+
150
+ ### Logical
151
+ `AND`, `OR`, `NOT`
152
+
153
+ ### Precedence (high to low)
154
+ `()` → `NOT` → `*`, `/` → `+`, `-` → comparisons → `AND` → `OR`
155
+
156
+ ---
157
+
158
+ ## User-Defined Functions
159
+ ```basic
160
+ DEF FN add$(a$, b$)
161
+ RETURN a$ + b$
162
+ END DEF
163
+ PRINT FN add$(3, 4) ' Call with FN prefix
164
+ ```
165
+ - Function name **must** end with `$`, called with `FN` prefix
166
+ - **Must be defined before called** (top of file or via INCLUDE)
167
+ - Parameters passed **by value**
168
+ - Completely isolated scope: no access to global variables, only global constants (`#`)
169
+ - Labels inside functions are local — GOTO/GOSUB **cannot** jump outside (error)
170
+ - Supports recursion
171
+ - Tip: put functions in separate files, `INCLUDE` at program start
172
+
173
+ ---
174
+
175
+ ## Control Flow
176
+
177
+ ### IF Statements
178
+ ```basic
179
+ ' Block IF (END IF and ENDIF both work)
180
+ IF x$ > 10 THEN
181
+ PRINT "big"
182
+ ELSEIF x$ > 5 THEN
183
+ PRINT "medium"
184
+ ELSE
185
+ PRINT "small"
186
+ ENDIF
187
+
188
+ ' One-line IF (GOTO/GOSUB only)
189
+ IF lives$ = 0 THEN GOTO [game_over]
190
+ IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [continue]
191
+ IF ready$ = 1 THEN GOSUB [start_game]
192
+ ```
193
+
194
+ ### FOR Loops
195
+ ```basic
196
+ FOR i$ = 1 TO 10 STEP 2 ' Auto-declares variable, STEP optional
197
+ PRINT i$
198
+ NEXT
199
+
200
+ FOR i$ = 10 TO 1 STEP -1 ' Count down
201
+ PRINT i$
202
+ NEXT
203
+ ```
204
+
205
+ ### WHILE Loops
206
+ ```basic
207
+ WHILE x$ < 100
208
+ x$ = x$ * 2
209
+ WEND
210
+ ```
211
+
212
+ ### Labels, GOTO, GOSUB
213
+ ```basic
214
+ [start]
215
+ GOSUB [subroutine]
216
+ GOTO [start]
217
+ END
218
+
219
+ [subroutine]
220
+ PRINT "Hello"
221
+ RETURN
222
+ ```
223
+
224
+ ### Dynamic Jumps (Labels as Variables)
225
+ ```basic
226
+ LET target$ = "[menu]"
227
+ GOTO target$ ' Variable holds label string
228
+ LET dest# = "[jump]"
229
+ GOSUB dest# ' Constants work too
230
+ ```
231
+
232
+ If you want to make a dynamic jump, use the "[" and "]" characters to indicate to BazzBasic that it is specifically a label.
233
+
234
+ ```basic
235
+ LET target$ = "[menu]" ' Correct way
236
+ LET target$ = "menu" ' Incorrect way
237
+ ```
238
+
239
+ ### Other
240
+ | Command | Description |
241
+ |---------|-------------|
242
+ | `SLEEP ms` | Pause execution |
243
+ | `END` | Terminate program |
244
+
245
+ ---
246
+
247
+ ## I/O Commands
248
+
249
+ | Command | Description |
250
+ |---------|-------------|
251
+ | `PRINT expr; expr` | Output (`;` = no space, `,` = tab) |
252
+ | `PRINT "text";` | Trailing `;` suppresses newline |
253
+ | `INPUT "prompt", var$` | Read input (splits on whitespace/comma) |
254
+ | `INPUT "prompt", a$, b$` | Read multiple values |
255
+ | `INPUT var$` | Default prompt `"? "` |
256
+ | `LINE INPUT "prompt", var$` | Read entire line including spaces |
257
+ | `CLS` | Clear screen |
258
+ | `LOCATE row, col` | Move cursor (1-based) |
259
+ | `COLOR fg, bg` | Set colors (0-15 palette) |
260
+ | `GETCONSOLE(row, col, type)` | Console read: 0=char(ASCII), 1=fg, 2=bg |
261
+ | `INKEY` | Non-blocking key check (0 if none, >256 for special keys) |
262
+ | `KEYDOWN(key#)` | Returns TRUE if specified key is currently held down |
263
+ | `WAITKEY(key#, key2#...)` | Halts program until requested key pressed |
264
+
265
+ ### INPUT vs LINE INPUT
266
+ | Feature | INPUT | LINE INPUT |
267
+ |---------|-------|------------|
268
+ | Reads spaces | No (splits) | Yes |
269
+ | Multiple variables | Yes | No |
270
+ | Default prompt | `"? "` | None |
271
+
272
+ ### INKEY vs KEYDOWN
273
+ | Feature | INKEY | KEYDOWN |
274
+ |---------|-------|---------|
275
+ | Returns | Key value or 0 | TRUE/FALSE |
276
+ | Key held | Reports once | Reports while held |
277
+ | Use case | Menu navigation | Game movement, held keys |
278
+
279
+ ```basic
280
+ ' KEYDOWN example — smooth movement
281
+ IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - 5
282
+ IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + 5
283
+ ```
284
+ ### WAITKEY
285
+ Halts the execution until requested key is pressed.
286
+ ```vb
287
+ ' Wait just the ENTER key
288
+ PRINT "ENTER"
289
+ PRINT WAITKEY(KEY_ENTER#) ' output: 13
290
+
291
+ ' Wait any of "a", "b" or "esc" keys
292
+ PRINT "A, B or ESC"
293
+ PRINT WAITKEY(KEY_A#, KEY_B#, KEY_ESC#) ' output: depends of your choice of key
294
+
295
+ PRINT "Press any key..."
296
+ LET a$ = WAITKEY()
297
+ PRINT a$ ' output: val of key you pressed
298
+ ```
299
+ ---
300
+
301
+ ## Math Functions
302
+
303
+ | Function | Description |
304
+ |----------|-------------|
305
+ | `ABS(n)` | Absolute value |
306
+ | `ATAN(n)` | Returns the arc tangent of n |
307
+ | `BETWEEN(n, min, max)` | TRUE if n is in range |
308
+ | `CEIL(n)` | Rounds up |
309
+ | `CINT(n)` | Convert to integer (rounds) |
310
+ | `COS(n)` | Returns the cosine of an angle |
311
+ | `CLAMP(n, min, max)` | Constrain value to range |
312
+ | `DEG(radians)` | Radians to degrees |
313
+ | `DISTANCE(x1,y1,x2,y2)` | 2D Euclidean distance |
314
+ | `DISTANCE(x1,y1,z1,x2,y2,z2)` | 3D Euclidean distance |
315
+ | `EXP(n)` | Exponential (e^n) |
316
+ | `FLOOR(n)` | Rounds down |
317
+ | `INT(n)` | Truncate toward zero |
318
+ | `LERP(start, end, t)` | Linear interpolation (t = 0.0-1.0) |
319
+ | `LOG(n)` | Natural log |
320
+ | `MAX(a, b)` | Returns higher from a & b |
321
+ | `MIN(a, b)` | Returns smaller from a & b |
322
+ | `MOD(a, b)` | Remainder |
323
+ | `POW(base, exp)` | Power |
324
+ | `RAD(degrees)` | Degrees to radians |
325
+ | `RND(n)` | Random 0 to n-1 |
326
+ | `ROUND(n)` | Standard rounding |
327
+ | `SGN(n)` | Sign (-1, 0, 1) |
328
+ | `SIN(n)` | Returns the sine of n |
329
+ | `SQR(n)` | Square root |
330
+ | `TAN(n)` | Returns the tangent of n |
331
+
332
+
333
+ ### Math Constants
334
+ | Constant | Value | Notes |
335
+ |----------|-------|-------|
336
+ | `PI` | 3.14159265358979 | 180° |
337
+ | `HPI` | 1.5707963267929895 | 90° (PI/2) |
338
+ | `QPI` | 0.7853981633974483 | 45° (PI/4) |
339
+ | `TAU` | 6.283185307179586 | 360° (PI*2) |
340
+ | `EULER` | 2.718281828459045 | e |
341
+
342
+ All are raw-coded values — no math at runtime, maximum performance.
343
+
344
+ ### Fast Trigonometry (Lookup Tables)
345
+ For graphics-intensive applications — ~20x faster than SIN/COS, 1-degree precision.
346
+
347
+ ```basic
348
+ FastTrig(TRUE) ' Enable lookup tables (~5.6 KB)
349
+
350
+ LET x$ = FastCos(45) ' Degrees, auto-normalized to 0-359
351
+ LET y$ = FastSin(90)
352
+ LET r$ = FastRad(180) ' Degrees to radians (doesn't need FastTrig)
353
+
354
+ FastTrig(FALSE) ' Free memory when done
355
+ ```
356
+
357
+ **Use FastTrig when:** raycasting, rotating sprites, particle systems, any loop calling trig hundreds of times per frame.
358
+ **Use regular SIN/COS when:** high precision needed, one-time calculations.
359
+
360
+ ---
361
+
362
+ ## String Functions
363
+
364
+ | Function | Description |
365
+ |----------|-------------|
366
+ | `ASC(s$)` | Character to ASCII code |
367
+ | `CHR(n)` | ASCII code to character |
368
+ | `INSTR(s$, search$)` | Find substring position (0 = not found) |
369
+ | `INSTR(start$, s$, search$)` | Find substring starting from position start$ (0 = not found) |
370
+ | `INVERT(s$)` | Inverts a string |
371
+ | `LCASE(s$)` | Converts to lowercase |
372
+ | `LEFT(s$, n)` | First n characters |
373
+ | `LEN(s$)` | String length |
374
+ | `LTRIM(s$)` | Left trim |
375
+ | `MID(s$, start, len)` | Substring (1-based) len optional |
376
+ | `REPEAT(s$, n)` | Repeat s$ for n times |
377
+ | `REPLACE(s$, old$, new$)` | Replace all occurrences |
378
+ | `RIGHT(s$, n)` | Last n characters |
379
+ | `RTRIM(s$)` | Right trim |
380
+ | `SPLIT(arr$, s$, delim$)` | Split into array |
381
+ | `SRAND(n)` | Returns random string length of n from allowed chars (letters, numbers and "_") |
382
+ | `STR(n)` | Number to string |
383
+ | `TRIM(s$)` | Remove leading/trailing spaces |
384
+ | `UCASE(s$)` | Converts to uppercase |
385
+ | `VAL(s$)` | String to number |
386
+
387
+ ### SPLIT example
388
+ ```vb
389
+ DIM parts$
390
+ REM Split with ","
391
+ LET count$ = SPLIT(parts$, "apple,banana,orange", ",")
392
+ PRINT "Parts: "; count$
393
+ PRINT parts$(0) ' "apple"
394
+ PRINT parts$(1) ' "banana"
395
+ PRINT parts$(2) ' "orange"
396
+ ```
397
+ ---
398
+
399
+ ## File I/O
400
+
401
+ ```basic
402
+ ' Simple text file
403
+ FileWrite "save.txt", data$
404
+ LET data$ = FileRead("save.txt")
405
+
406
+ ' Array read/write (key=value format)
407
+ DIM a$
408
+ a$("name") = "player1"
409
+ a$("score") = 9999
410
+ FileWrite "scores.txt", a$
411
+
412
+ DIM b$
413
+ LET b$ = FileRead("scores.txt")
414
+ PRINT b$("name") ' Output: player1
415
+ ```
416
+
417
+ **Array file format:**
418
+ ```
419
+ name=player1
420
+ score=9999
421
+ multi,dim,key=value
422
+ ```
423
+
424
+ | Function/Command | Description |
425
+ |---------|-------------|
426
+ | `FileRead(path)` | Read file; returns string or populates array |
427
+ | `FileWrite path, data` | Write string or array to file |
428
+ | `FileExists(path)` | Returns 1 if file exists, 0 if not |
429
+ | `FileDelete path` | Delete a file |
430
+ | `FileList(path$, arr$)` | List files in directory into array |
431
+
432
+ ---
433
+
434
+ ## Network (HTTP)
435
+
436
+ ```basic
437
+ DIM response$
438
+ LET response$ = HTTPGET("https://api.example.com/data")
439
+ PRINT response$
440
+
441
+ DIM result$
442
+ LET result$ = HTTPPOST("https://api.example.com/post", "{""key"":""value""}")
443
+ PRINT result$
444
+ ```
445
+
446
+ - Returns response body as string
447
+ - Supports HTTPS
448
+ - Use `""` inside strings to escape quotes in JSON bodies
449
+ - Timeout handled gracefully — returns error message string on failure
450
+
451
+ ---
452
+
453
+ ## Sound (SDL2_mixer)
454
+
455
+ ```basic
456
+ DIM bgm$
457
+ LET bgm$ = LOADSOUND("music.wav")
458
+ LET sfx$ = LOADSOUND("jump.wav")
459
+
460
+ SOUNDREPEAT(bgm$) ' Loop continuously
461
+ SOUNDONCE(sfx$) ' Play once
462
+ SOUNDSTOP(bgm$) ' Stop specific sound
463
+ SOUNDSTOPALL ' Stop all sounds
464
+ ```
465
+
466
+ | Command | Description |
467
+ |---------|-------------|
468
+ | `LOADSOUND(path)` | Load sound file, returns ID |
469
+ | `SOUNDONCE(id$)` | Play once |
470
+ | `SOUNDREPEAT(id$)` | Loop continuously |
471
+ | `SOUNDSTOP(id$)` | Stop specific sound |
472
+ | `SOUNDSTOPALL` | Stop all sounds |
473
+
474
+ - Formats: WAV (recommended), MP3, others via SDL2_mixer
475
+ - Thread-safe, multiple simultaneous sounds supported
476
+ - Load sounds once at startup for performance
477
+
478
+ ---
479
+
480
+ ## Graphics (SDL2)
481
+
482
+ ### Screen Setup
483
+ ```basic
484
+ SCREEN 12 ' 640x480 VGA mode
485
+ SCREEN 0, 800, 600, "Title" ' Custom size with title
486
+ ```
487
+ Modes: 0=640x400, 1=320x200, 2=640x350, 7=320x200, 9=640x350, 12=640x480, 13=320x200
488
+
489
+ ### Fullscreen
490
+ ```basic
491
+ FULLSCREEN TRUE ' Borderless fullscreen
492
+ FULLSCREEN FALSE ' Windowed mode
493
+ ```
494
+ Call after `SCREEN`.
495
+
496
+ ### VSync
497
+ ```basic
498
+ VSYNC(TRUE) ' Enable (default) — caps to monitor refresh
499
+ VSYNC(FALSE) ' Disable — unlimited FPS, may tear
500
+ ```
501
+
502
+ ### Double Buffering (Required for Animation)
503
+ ```basic
504
+ SCREENLOCK ON ' Start buffering
505
+ ' ... draw commands ...
506
+ SCREENLOCK OFF ' Display frame
507
+ SLEEP 16 ' ~60 FPS
508
+ ```
509
+ `SCREENLOCK` without argument = `SCREENLOCK ON`. Do math/logic outside SCREENLOCK block.
510
+
511
+ ### Drawing Primitives
512
+ | Command | Description |
513
+ |---------|-------------|
514
+ | `PSET (x, y), color` | Draw pixel |
515
+ | `POINT(x, y)` | Read pixel color (returns RGB integer) |
516
+ | `LINE (x1,y1)-(x2,y2), color` | Draw line |
517
+ | `LINE (x1,y1)-(x2,y2), color, B` | Box outline |
518
+ | `LINE (x1,y1)-(x2,y2), color, BF` | Filled box (faster than CLS) |
519
+ | `CIRCLE (cx, cy), r, color` | Circle outline |
520
+ | `CIRCLE (cx, cy), r, color, 1` | Filled circle |
521
+ | `PAINT (x, y), fill, border` | Flood fill |
522
+ | `RGB(r, g, b)` | Create color (0-255 each) |
523
+
524
+ ### Shape/Sprite System
525
+ ```basic
526
+ DIM sprite$
527
+ sprite$ = LOADSHAPE("RECTANGLE", 50, 50, RGB(255,0,0)) ' Types: RECTANGLE, CIRCLE, TRIANGLE
528
+ sprite$ = LOADIMAGE("player.png") ' PNG (with alpha) or BMP
529
+
530
+ MOVESHAPE sprite$, x, y ' Position (top-left point)
531
+ ROTATESHAPE sprite$, angle ' Absolute degrees
532
+ SCALESHAPE sprite$, 1.5 ' 1.0 = original
533
+ SHOWSHAPE sprite$
534
+ HIDESHAPE sprite$
535
+ DRAWSHAPE sprite$ ' Render
536
+ REMOVESHAPE sprite$ ' Free memory
537
+ ```
538
+ - PNG recommended (full alpha transparency 0-255), BMP for legacy
539
+ - Images positioned by their **top-left point**
540
+ - Rotation is absolute, not cumulative
541
+ - Always REMOVESHAPE when done to free memory
542
+
543
+ ### LOADIMAGE with url
544
+ ```vb
545
+ LET sprite$ = LOADIMAGE("https://example.com/sprite.png")
546
+ ' → downloads "sprite.png" to root of your program
547
+ ' → sprite$ works just as with normal file load
548
+
549
+ ' to remove or move the downloaded file
550
+ SHELL("move sprite.png images\sprite.png") ' move to subfolder
551
+ ' or
552
+ FileDelete "sprite.png" ' just delete it
553
+ ```
554
+
555
+ ### Sprite Sheets (LOADSHEET)
556
+ ```basic
557
+ DIM sprites$
558
+ LOADSHEET sprites$, spriteW, spriteH, "sheet.png"
559
+
560
+ ' Access sprites by 1-based index
561
+ MOVESHAPE sprites$(index$), x#, y#
562
+ DRAWSHAPE sprites$(index$)
563
+ ```
564
+ - Sprites indexed left-to-right, top-to-bottom starting at 1
565
+ - All sprites must be same size (spriteW x spriteH)
566
+
567
+ ### Mouse Input (Graphics Mode Only)
568
+ | Function | Description |
569
+ |----------|-------------|
570
+ | `MOUSEX` / `MOUSEY` | Cursor position |
571
+ | `MOUSEB` | Button state (bitmask, use `AND`) |
572
+
573
+ Button constants: `MOUSE_LEFT#`=1, `MOUSE_RIGHT#`=2, `MOUSE_MIDDLE#`=4
574
+
575
+ ### Color Palette (0-15)
576
+ | 0 Black | 4 Red | 8 Dark Gray | 12 Light Red |
577
+ |---------|-------|-------------|--------------|
578
+ | 1 Blue | 5 Magenta | 9 Light Blue | 13 Light Magenta |
579
+ | 2 Green | 6 Brown | 10 Light Green | 14 Yellow |
580
+ | 3 Cyan | 7 Light Gray | 11 Light Cyan | 15 White |
581
+
582
+ ### Performance Tips
583
+ 1. Use `SCREENLOCK ON/OFF` for all animation
584
+ 2. `LINE...BF` is faster than `CLS` for clearing
585
+ 3. Store `RGB()` values in constants
586
+ 4. REMOVESHAPE unused shapes
587
+ 5. SLEEP 16 for ~60 FPS
588
+ 6. Do math/logic outside SCREENLOCK block
589
+
590
+ ---
591
+
592
+ ## Built-in Constants
593
+
594
+ ### Arrow Keys
595
+ | | | |
596
+ |---|---|---|
597
+ | `KEY_UP#` | `KEY_DOWN#` | `KEY_LEFT#` |
598
+ | `KEY_RIGHT#` | | |
599
+
600
+ ### Special Keys
601
+ | | | |
602
+ |---|---|---|
603
+ | `KEY_ESC#` | `KEY_TAB#` | `KEY_BACKSPACE#` |
604
+ | `KEY_ENTER#` | `KEY_SPACE#` | `KEY_INSERT#` |
605
+ | `KEY_DELETE#` | `KEY_HOME#` | `KEY_END#` |
606
+ | `KEY_PGUP#` | `KEY_PGDN#` | |
607
+
608
+ ### Modifier Keys
609
+ | | | |
610
+ |---|---|---|
611
+ | `KEY_LSHIFT#` | `KEY_RSHIFT#` | `KEY_LCTRL#` |
612
+ | `KEY_RCTRL#` | `KEY_LALT#` | `KEY_RALT#` |
613
+ | `KEY_LWIN#` | `KEY_RWIN#` | |
614
+
615
+ ### Function Keys
616
+ | | | |
617
+ |---|---|---|
618
+ | `KEY_F1#` | `KEY_F2#` | `KEY_F3#` |
619
+ | `KEY_F4#` | `KEY_F5#` | `KEY_F6#` |
620
+ | `KEY_F7#` | `KEY_F8#` | `KEY_F9#` |
621
+ | `KEY_F10#` | `KEY_F11#` | `KEY_F12#` |
622
+
623
+ ### Numpad Keys
624
+ | | | |
625
+ |---|---|---|
626
+ | `KEY_NUMPAD0#` | `KEY_NUMPAD1#` | `KEY_NUMPAD2#` |
627
+ | `KEY_NUMPAD3#` | `KEY_NUMPAD4#` | `KEY_NUMPAD5#` |
628
+ | `KEY_NUMPAD6#` | `KEY_NUMPAD7#` | `KEY_NUMPAD8#` |
629
+ | `KEY_NUMPAD9#` | | |
630
+
631
+ ### Punctuation Keys
632
+ | | | |
633
+ |---|---|---|
634
+ | `KEY_COMMA#` | `KEY_DOT#` | `KEY_MINUS#` |
635
+ | `KEY_EQUALS#` | `KEY_SLASH#` | `KEY_BACKSLASH#` |
636
+ | `KEY_SEP#` | `KEY_GRAVE#` | `KEY_LBRACKET#` |
637
+ | `KEY_RBRACKET#` | | |
638
+
639
+ ### Alphabet Keys
640
+ | | | |
641
+ |---|---|---|
642
+ | `KEY_A#` | `KEY_B#` | `KEY_C#` |
643
+ | `KEY_D#` | `KEY_E#` | `KEY_F#` |
644
+ | `KEY_G#` | `KEY_H#` | `KEY_I#` |
645
+ | `KEY_J#` | `KEY_K#` | `KEY_L#` |
646
+ | `KEY_M#` | `KEY_N#` | `KEY_O#` |
647
+ | `KEY_P#` | `KEY_Q#` | `KEY_R#` |
648
+ | `KEY_S#` | `KEY_T#` | `KEY_U#` |
649
+ | `KEY_V#` | `KEY_W#` | `KEY_X#` |
650
+ | `KEY_Y#` | `KEY_Z#` | |
651
+
652
+ ### Number Keys
653
+ | | | |
654
+ |---|---|---|
655
+ | `KEY_0#` | `KEY_1#` | `KEY_2#` |
656
+ | `KEY_3#` | `KEY_4#` | `KEY_5#` |
657
+ | `KEY_6#` | `KEY_7#` | `KEY_8#` |
658
+ | `KEY_9#` | | |
659
+
660
+ ### Mouse
661
+ ```basic
662
+ MOUSE_LEFT# = 1, MOUSE_RIGHT# = 2, MOUSE_MIDDLE# = 4
663
+ ```
664
+
665
+ ### Logical
666
+ `TRUE` = 1, `FALSE` = 0
667
+
668
+ ---
669
+
670
+ ## TIME & TICKS
671
+
672
+ ### TIME(format$)
673
+ Returns current date/time as a formatted string. Uses .NET DateTime format strings.
674
+ ```vb
675
+ PRINT TIME() ' Default: "16:30:45"
676
+ PRINT TIME("HH:mm:ss") ' "16:30:45"
677
+ PRINT TIME("dd.MM.yyyy") ' "09.01.2026"
678
+ PRINT TIME("yyyy-MM-dd") ' "2026-01-09"
679
+ PRINT TIME("dddd") ' "Friday"
680
+ PRINT TIME("MMMM") ' "January"
681
+ PRINT TIME("dd MMMM yyyy") ' "09 January 2026"
682
+ PRINT TIME("HH:mm") ' "16:30"
683
+ ```
684
+
685
+ **Common format codes:**
686
+ | Code | Description | Example |
687
+ |------|-------------|--------|
688
+ | HH | Hour (00-23) | 16 |
689
+ | mm | Minutes | 30 |
690
+ | ss | Seconds | 45 |
691
+ | dd | Day | 09 |
692
+ | MM | Month (number) | 01 |
693
+ | MMM | Month (short) | Jan |
694
+ | MMMM | Month (full) | January |
695
+ | yy | Year (2 digits) | 26 |
696
+ | yyyy | Year (4 digits) | 2026 |
697
+ | ddd | Weekday (short) | Fri |
698
+ | dddd | Weekday (full) | Friday |
699
+
700
+
701
+ ### TICKS
702
+ Returns milliseconds elapsed since program started. Useful for timing, animations, and game loops.
703
+ ```vb
704
+ LET start$ = TICKS
705
+
706
+ ' Do some work
707
+ FOR i$ = 1 TO 10000
708
+ LET x$ = x$ + 1
709
+ NEXT
710
+
711
+ LET elapsed$ = TICKS - start$
712
+ PRINT "Time taken: "; elapsed$; " ms"
713
+ ```
714
+ ## Source Control
715
+
716
+ ### INCLUDE
717
+ ```basic
718
+ INCLUDE "other_file.bas" ' Insert source at this point
719
+ INCLUDE "MathLib.bb" ' Include compiled library
720
+ ```
721
+
722
+ ### Libraries (.bb files)
723
+ ```basic
724
+ ' MathLib.bas — can ONLY contain DEF FN functions
725
+ DEF FN add$(x$, y$)
726
+ RETURN x$ + y$
727
+ END DEF
728
+ ```
729
+ Compile: `bazzbasic.exe -lib MathLib.bas` → `MathLib.bb`
730
+
731
+ ```basic
732
+ INCLUDE "MathLib.bb"
733
+ PRINT FN MATHLIB_add$(5, 3) ' Auto-prefix: FILENAME_ + functionName
734
+ ```
735
+ - Libraries can only contain `DEF FN` functions
736
+ - Library functions can access main program constants (`#`)
737
+ - Version-locked: .bb may not work across BazzBasic versions
738
+
739
+ ---
740
+
741
+ ## Common Patterns
742
+
743
+ ### Game Loop
744
+ ```basic
745
+ SCREEN 12
746
+ LET running$ = TRUE
747
+
748
+ WHILE running$
749
+ LET key$ = INKEY
750
+ IF key$ = KEY_ESC# THEN running$ = FALSE
751
+
752
+ ' Math and logic here
753
+
754
+ SCREENLOCK ON
755
+ LINE (0,0)-(640,480), 0, BF ' Fast clear
756
+ ' Draw game state
757
+ SCREENLOCK OFF
758
+ SLEEP 16
759
+ WEND
760
+ END
761
+ ```
762
+
763
+ ### HTTP + Data
764
+ ```basic
765
+ DIM response$
766
+ LET response$ = HTTPGET("https://api.example.com/scores")
767
+ PRINT response$
768
+
769
+ DIM payload$
770
+ LET payload$ = HTTPPOST("https://api.example.com/submit", "{""score"":9999}")
771
+ PRINT payload$
772
+ ```
773
+
774
+ ### Save/Load with Arrays
775
+ ```basic
776
+ DIM save$
777
+ save$("level") = 3
778
+ save$("hp") = 80
779
+ FileWrite "save.txt", save$
780
+
781
+ DIM load$
782
+ LET load$ = FileRead("save.txt")
783
+ PRINT load$("level") ' Output: 3
784
+ ```
785
+
786
+ ## Arrays and JSON
787
+
788
+ BazzBasic arrays map naturally to JSON. Nested JSON objects and arrays become multi-dimensional keys using comma-separated indices.
789
+
790
+ ### ASJSON
791
+ Converts a BazzBasic array to a JSON string:
792
+ ```vb
793
+ DIM player$
794
+ player$("name") = "Alice"
795
+ player$("score") = 9999
796
+ player$("address,city") = "New York"
797
+ player$("skills,0") = "JavaScript"
798
+ player$("skills,1") = "Python"
799
+
800
+ LET json$ = ASJSON(player$)
801
+ PRINT json$
802
+ ' Output: {"name":"Alice","score":9999,"address":{"city":"New York"},"skills":["JavaScript","Python"]}
803
+ ```
804
+
805
+ ### ASARRAY
806
+ Converts a JSON string into a BazzBasic array. Returns number of elements loaded:
807
+ ```vb
808
+ DIM data$
809
+ LET count$ = ASARRAY(data$, "{""name"":""Bob"",""score"":42}")
810
+
811
+ PRINT data$("name") ' Output: Bob
812
+ PRINT data$("score") ' Output: 42
813
+ PRINT count$ ' Output: 2
814
+ ```
815
+
816
+ Nested JSON becomes comma-separated keys:
817
+ ```vb
818
+ DIM data$
819
+ LET json$ = "{""player"":{""name"":""Alice"",""hp"":100},""skills"":[""fire"",""ice""]}"
820
+ ASARRAY data$, json$
821
+
822
+ PRINT data$("player,name") ' Output: Alice
823
+ PRINT data$("player,hp") ' Output: 100
824
+ PRINT data$("skills,0") ' Output: fire
825
+ PRINT data$("skills,1") ' Output: ice
826
+ ```
827
+
828
+ ### LOADJSON
829
+ Loads a JSON file directly into an array:
830
+ ```vb
831
+ DIM scores$
832
+ LOADJSON scores$, "highscores.json"
833
+
834
+ PRINT scores$("first,name") ' Output: depends on file contents
835
+ ```
836
+
837
+ ### SAVEJSON
838
+ Saves an array as a formatted JSON file:
839
+ ```vb
840
+ DIM save$
841
+ save$("level") = 3
842
+ save$("hp") = 80
843
+ save$("position,x") = 100
844
+ save$("position,y") = 200
845
+
846
+ SAVEJSON save$, "savegame.json"
847
+ ```
848
+
849
+ The resulting `savegame.json`:
850
+ ```json
851
+ {
852
+ "level": 3,
853
+ "hp": 80,
854
+ "position": {
855
+ "x": 100,
856
+ "y": 200
857
+ }
858
+ }
859
+ ```
860
+
861
+ ### Practical example: HTTP API + JSON
862
+ ```vb
863
+ DIM response$
864
+ LET raw$ = HTTPGET("https://api.example.com/user/1")
865
+ ASARRAY response$, raw$
866
+
867
+ PRINT "Name: "; response$("name")
868
+ PRINT "Email: "; response$("email")
869
+ ```
870
+
871
+ ### Sound with Graphics
872
+ ```basic
873
+ SCREEN 12
874
+ LET bgm$ = LOADSOUND("music.wav")
875
+ LET sfx$ = LOADSOUND("jump.wav")
876
+ SOUNDREPEAT(bgm$)
877
+
878
+ WHILE INKEY <> KEY_ESC#
879
+ IF INKEY = KEY_SPACE# THEN SOUNDONCE(sfx$)
880
+ SLEEP 16
881
+ WEND
882
+ SOUNDSTOPALL
883
+ END
884
+ ```
885
+
886
+ ---
887
+
888
+ ## Code Style Conventions
889
+
890
+ **Variables** — `camelCase$`
891
+ ```basic
892
+ LET playerName$ = "Hero"
893
+ LET score$ = 0
894
+ ```
895
+
896
+ **Constants** — `UPPER_SNAKE_CASE#`
897
+ ```basic
898
+ LET MAX_HEALTH# = 100
899
+ LET SCREEN_W# = 640
900
+ ```
901
+
902
+ **Arrays** — `camelCase$` (like variables, declared with DIM)
903
+ ```basic
904
+ DIM scores$
905
+ DIM playerData$
906
+ ```
907
+
908
+ **User-defined functions** — `PascalCase$`
909
+ ```basic
910
+ DEF FN CalculateDamage$(attack$, defence$)
911
+ DEF FN IsColliding$(x$, y$)
912
+ ```
913
+
914
+ **Labels** — descriptive names, `[sub:]` prefix recommended for subroutines
915
+ ```basic
916
+ [sub:DrawPlayer] ' Subroutine
917
+ [gameLoop] ' Jump target
918
+ ```
919
+
920
+ ### Program Structure
921
+ 1. Constants first
922
+ 2. User-defined functions (or INCLUDE them)
923
+ 3. Main program loop
924
+ 4. Subroutines (labels) last
925
+
926
+ ```basic
927
+ ' ── 1. CONSTANTS ────────────────────────────
928
+ ' or INCLUDE as "constants.bas" etc
929
+
930
+ LET SCREEN_W# = 640
931
+ LET SCREEN_H# = 480
932
+ LET MAX_SPEED# = 5
933
+
934
+ ' ── 2. FUNCTIONS ────────────────────────────
935
+ ' or INCLUDE as "functions.bas" etc
936
+ DEF FN Clamp$(val$, lo$, hi$)
937
+ IF val$ < lo$ THEN RETURN lo$
938
+ IF val$ > hi$ THEN RETURN hi$
939
+ RETURN val$
940
+ END DEF
941
+
942
+ ' ── 3. INIT ─────────────────────────────────
943
+ ' or INCLUDE as "inits.bas" etc
944
+ [inits]
945
+ SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
946
+ LET x$ = 100
947
+ LET y$ = 100
948
+ LET running$ = TRUE
949
+
950
+ ' ── 4. MAIN LOOP ────────────────────────────
951
+ [main]
952
+ WHILE running$
953
+ IF INKEY = KEY_ESC# THEN running$ = FALSE
954
+ GOSUB [sub:update]
955
+ GOSUB [sub:draw]
956
+ SLEEP 16
957
+ WEND
958
+ END
959
+
960
+ ' ── 5. SUBROUTINES ──────────────────────────
961
+ ' or INCLUDE as "subs.bas" etc
962
+
963
+ ' IMPORTANT:
964
+ ' Avoid declaring variables outside INIT if speed matters.
965
+ ' If done here, Bazzbasic has to check the existence of the variable in each call.
966
+ [sub:update]
967
+ IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED#
968
+ IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED#
969
+ RETURN
970
+
971
+ [sub:draw]
972
+ SCREENLOCK ON
973
+ LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
974
+ CIRCLE (x$, y$), 10, RGB(0,255,0), 1
975
+ SCREENLOCK OFF
976
+ RETURN
977
+ ```
978
+
979
+ ### Subroutine Indentation
980
+ ```basic
981
+ [sub:DrawPlayer]
982
+ MOVESHAPE player$, x$, y$
983
+ DRAWSHAPE player$
984
+ RETURN
985
+ ```