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

Delete BazzBasic-AI-guide-19032026.md

Browse files
Files changed (1) hide show
  1. BazzBasic-AI-guide-19032026.md +0 -765
BazzBasic-AI-guide-19032026.md DELETED
@@ -1,765 +0,0 @@
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
- **Hugginface AI manual:** https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
26
- **Examples:** "https://github.com/EkBass/BazzBasic/tree/main/Examples"
27
- **Github_repo:** "https://github.com/EkBass/BazzBasic"
28
- **Github_discussions:** "https://github.com/EkBass/BazzBasic/discussions"
29
- **Discord_channel:** "https://discord.com/channels/682603735515529216/1464283741919907932"
30
- **Thinbasic subforum:** "https://www.thinbasic.com/community/forumdisplay.php?401-BazzBasic"
31
-
32
- ## Usage:
33
- This file is created as a guide specifically for the AI. With this, the AI can not only code itself with BazzBasic, but also guide the user with it.
34
-
35
- Feed the file as it is to the AI, as an attachment, as a project file, etc.
36
-
37
- ## Few examples:
38
- **raycaster_3d:** https://raw.githubusercontent.com/EkBass/BazzBasic/refs/heads/main/Examples/raycaster_3d_optimized.bas
39
- **voxel_terrain:** https://raw.githubusercontent.com/EkBass/BazzBasic/refs/heads/main/Examples/voxel_terrain.bas
40
- **sprite load:** https://github.com/EkBass/BazzBasic/blob/main/Examples/countdown_demo.bas
41
- **Eliza:** https://github.com/EkBass/BazzBasic/blob/main/Examples/Eliza.bas
42
-
43
- ## CLI Usage
44
-
45
- | Command | Action |
46
- |---------|--------|
47
- | `bazzbasic.exe` | Launch IDE |
48
- | `bazzbasic.exe file.bas` | Run program |
49
- | `bazzbasic.exe -exe file.bas` | Create standalone .exe |
50
- | `bazzbasic.exe -lib file.bas` | Create tokenized library (.bb) |
51
-
52
- 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.
53
-
54
- ### External syntax colors.
55
- 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.
56
-
57
- There are syntax color files for *Notepad++*, *Geany* and *Visual Studio Code* available at https://github.com/EkBass/BazzBasic/tree/main/extras
58
-
59
- ---
60
-
61
- ## Syntax Fundamentals
62
-
63
- ### Variables and Constants
64
- Forget traditional BASIC types. Suffixes in BazzBasic define mutability, not data type.
65
-
66
- Variables and arrays in BazzBasic are typeless: hold numbers or strings interchangeably
67
-
68
- - $ = Mutable Variable
69
- - # = Immutable Constant
70
-
71
-
72
- ```basic
73
- LET a$ ' Declare without value
74
- LET name$ = "Alice" ' Variable, string (mutable, $ suffix)
75
- LET age$ = 19 ' Variable, integer (mutable, $ suffix)
76
- LET price$ = 1.99 ' Variable, decimal (mutable, $ suffix)
77
- LET PI# = 3.14159 ' Constant (immutable, # suffix)
78
- LET x$, y$, z$ = 10 ' Multiple declaration
79
- ```
80
- - All variables require `$` suffix, constants require `#`
81
- - Typeless: hold numbers or strings interchangeably
82
- - Must declare with `LET` before use (except FOR/INPUT which auto-declare)
83
- - Assignment after declaration: `x$ = x$ + 1` (no LET needed)
84
- - **Case-insensitive**: `PRINT`, `print`, `Print` all work
85
- - Naming: letters, numbers, underscores; cannot start with number
86
-
87
- ### Comparison Behavior
88
- `"123" = 123` is TRUE (cross-type comparison), but slower — keep types consistent.
89
-
90
- ### Scope
91
- - Main code shares one scope (even inside IF blocks)
92
- - `DEF FN` functions have completely isolated scope
93
- - Only global constants (`#`) are accessible inside functions
94
-
95
- ### Multiple Statements Per Line
96
- ```basic
97
- COLOR 14, 0 : CLS : PRINT "Hello"
98
- ```
99
-
100
- ### Comments
101
- ```basic
102
- REM This is a comment
103
- ' This is also a comment
104
- PRINT "Hello" ' Inline comment
105
- ```
106
-
107
- ### Escape Sequences in Strings
108
- | Sequence | Result |
109
- |----------|--------|
110
- | `\"` | Quote |
111
- | `\n` | Newline |
112
- | `\t` | Tab |
113
- | `\\` | Backslash |
114
-
115
- ---
116
-
117
- ## Arrays
118
- ```basic
119
- DIM scores$ ' Declare (must use DIM)
120
- DIM a$, b$, c$ ' Multiple declaration
121
- scores$(0) = 95 ' Numeric index (0-based)
122
- scores$("name") = "Alice" ' String key (associative)
123
- matrix$(0, 1) = "A2" ' Multi-dimensional
124
- data$(1, "header") = "Name" ' Mixed indexing
125
- ```
126
- - Array names must end with `$`
127
- - Fully dynamic: numeric, string, multi-dimensional, mixed indexing
128
- - Arrays **cannot** be passed directly to functions — pass values of individual elements
129
- - Accessing uninitialized elements is an error — check with `HASKEY` first
130
-
131
- ### Array Functions
132
- | Function | Description |
133
- |----------|-------------|
134
- | `LEN(arr$())` | Element count (note: empty parens) |
135
- | `HASKEY(arr$(key))` | 1 if exists, 0 if not |
136
- | `DELKEY arr$(key)` | Remove element |
137
- | `DELARRAY arr$` | Remove entire array (can re-DIM after) |
138
-
139
- ---
140
-
141
- ## Operators
142
-
143
- ### Arithmetic
144
- `+` (add/concatenate), `-`, `*`, `/` (returns float)
145
-
146
- ### Comparison
147
- `=` or `==`, `<>` or `!=`, `<`, `>`, `<=`, `>=`
148
-
149
- ### Logical
150
- `AND`, `OR`, `NOT`
151
-
152
- ### Precedence (high to low)
153
- `()` → `NOT` → `*`, `/` → `+`, `-` → comparisons → `AND` → `OR`
154
-
155
- ---
156
-
157
- ## User-Defined Functions
158
- ```basic
159
- DEF FN add$(a$, b$)
160
- RETURN a$ + b$
161
- END DEF
162
- PRINT FN add$(3, 4) ' Call with FN prefix
163
- ```
164
- - Function name **must** end with `$`, called with `FN` prefix
165
- - **Must be defined before called** (top of file or via INCLUDE)
166
- - Parameters passed **by value**
167
- - Completely isolated scope: no access to global variables, only global constants (`#`)
168
- - Labels inside functions are local — GOTO/GOSUB **cannot** jump outside (error)
169
- - Supports recursion
170
- - Tip: put functions in separate files, `INCLUDE` at program start
171
-
172
- ---
173
-
174
- ## Control Flow
175
-
176
- ### IF Statements
177
- ```basic
178
- ' Block IF (END IF and ENDIF both work)
179
- IF x$ > 10 THEN
180
- PRINT "big"
181
- ELSEIF x$ > 5 THEN
182
- PRINT "medium"
183
- ELSE
184
- PRINT "small"
185
- ENDIF
186
-
187
- ' One-line IF (GOTO/GOSUB only)
188
- IF lives$ = 0 THEN GOTO [game_over]
189
- IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [continue]
190
- IF ready$ = 1 THEN GOSUB [start_game]
191
- ```
192
-
193
- ### FOR Loops
194
- ```basic
195
- FOR i$ = 1 TO 10 STEP 2 ' Auto-declares variable, STEP optional
196
- PRINT i$
197
- NEXT
198
-
199
- FOR i$ = 10 TO 1 STEP -1 ' Count down
200
- PRINT i$
201
- NEXT
202
- ```
203
-
204
- ### WHILE Loops
205
- ```basic
206
- WHILE x$ < 100
207
- x$ = x$ * 2
208
- WEND
209
- ```
210
-
211
- ### Labels, GOTO, GOSUB
212
- ```basic
213
- [start]
214
- GOSUB [subroutine]
215
- GOTO [start]
216
- END
217
-
218
- [subroutine]
219
- PRINT "Hello"
220
- RETURN
221
- ```
222
-
223
- ### Dynamic Jumps (Labels as Variables)
224
- ```basic
225
- LET target$ = "[menu]"
226
- GOTO target$ ' Variable holds label string
227
- LET dest# = "[jump]"
228
- GOSUB dest# ' Constants work too
229
- ```
230
-
231
- If you want to make a dynamic jump, use the "[" and "]" characters to indicate to BazzBasic that it is specifically a label.
232
-
233
- ```basic
234
- LET target$ = "[menu]" ' Correct way
235
- LET target$ = "menu" ' Incorrect way
236
- ```
237
-
238
- ### Other
239
- | Command | Description |
240
- |---------|-------------|
241
- | `SLEEP ms` | Pause execution |
242
- | `END` | Terminate program |
243
-
244
- ---
245
-
246
- ## I/O Commands
247
-
248
- | Command | Description |
249
- |---------|-------------|
250
- | `PRINT expr; expr` | Output (`;` = no space, `,` = tab) |
251
- | `PRINT "text";` | Trailing `;` suppresses newline |
252
- | `INPUT "prompt", var$` | Read input (splits on whitespace/comma) |
253
- | `INPUT "prompt", a$, b$` | Read multiple values |
254
- | `INPUT var$` | Default prompt `"? "` |
255
- | `LINE INPUT "prompt", var$` | Read entire line including spaces |
256
- | `CLS` | Clear screen |
257
- | `LOCATE row, col` | Move cursor (1-based) |
258
- | `COLOR fg, bg` | Set colors (0-15 palette) |
259
- | `GETCONSOLE(row, col, type)` | Console read: 0=char(ASCII), 1=fg, 2=bg |
260
- | `INKEY` | Non-blocking key check (0 if none, >256 for special keys) |
261
- | `KEYDOWN(key#)` | Returns TRUE if specified key is currently held down |
262
-
263
- ### INPUT vs LINE INPUT
264
- | Feature | INPUT | LINE INPUT |
265
- |---------|-------|------------|
266
- | Reads spaces | No (splits) | Yes |
267
- | Multiple variables | Yes | No |
268
- | Default prompt | `"? "` | None |
269
-
270
- ### INKEY vs KEYDOWN
271
- | Feature | INKEY | KEYDOWN |
272
- |---------|-------|---------|
273
- | Returns | Key value or 0 | TRUE/FALSE |
274
- | Key held | Reports once | Reports while held |
275
- | Use case | Menu navigation | Game movement, held keys |
276
-
277
- ```basic
278
- ' KEYDOWN example — smooth movement
279
- IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - 5
280
- IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + 5
281
- ```
282
-
283
- ---
284
-
285
- ## Math Functions
286
-
287
- | Function | Description |
288
- |----------|-------------|
289
- | `ABS(n)` | Absolute value |
290
- | `ATAN(n)` | Returns the arc tangent of n |
291
- | `BETWEEN(n, min, max)` | TRUE if n is in range |
292
- | `CEIL(n)` | Rounds up |
293
- | `CINT(n)` | Convert to integer (rounds) |
294
- | `COS(n)` | Returns the cosine of an angle |
295
- | `CLAMP(n, min, max)` | Constrain value to range |
296
- | `DEG(radians)` | Radians to degrees |
297
- | `DISTANCE(x1,y1,x2,y2)` | 2D Euclidean distance |
298
- | `DISTANCE(x1,y1,z1,x2,y2,z2)` | 3D Euclidean distance |
299
- | `EXP(n)` | Exponential (e^n) |
300
- | `FLOOR(n)` | Rounds down |
301
- | `INT(n)` | Truncate toward zero |
302
- | `LERP(start, end, t)` | Linear interpolation (t = 0.0-1.0) |
303
- | `LOG(n)` | Natural log |
304
- | `MAX(a, b)` | Returns higher from a & b |
305
- | `MIN(a, b)` | Returns smaller from a & b |
306
- | `MOD(a, b)` | Remainder |
307
- | `POW(base, exp)` | Power |
308
- | `RAD(degrees)` | Degrees to radians |
309
- | `RND(n)` | Random 0 to n-1 |
310
- | `ROUND(n)` | Standard rounding |
311
- | `SGN(n)` | Sign (-1, 0, 1) |
312
- | `SIN(n)` | Returns the sine of n |
313
- | `SQR(n)` | Square root |
314
- | `TAN(n)` | Returns the tangent of n |
315
-
316
-
317
- ### Math Constants
318
- | Constant | Value | Notes |
319
- |----------|-------|-------|
320
- | `PI` | 3.14159265358979 | 180° |
321
- | `HPI` | 1.5707963267929895 | 90° (PI/2) |
322
- | `QPI` | 0.7853981633974483 | 45° (PI/4) |
323
- | `TAU` | 6.283185307179586 | 360° (PI*2) |
324
- | `EULER` | 2.718281828459045 | e |
325
-
326
- All are raw-coded values — no math at runtime, maximum performance.
327
-
328
- ### Fast Trigonometry (Lookup Tables)
329
- For graphics-intensive applications — ~20x faster than SIN/COS, 1-degree precision.
330
-
331
- ```basic
332
- FastTrig(TRUE) ' Enable lookup tables (~5.6 KB)
333
-
334
- LET x$ = FastCos(45) ' Degrees, auto-normalized to 0-359
335
- LET y$ = FastSin(90)
336
- LET r$ = FastRad(180) ' Degrees to radians (doesn't need FastTrig)
337
-
338
- FastTrig(FALSE) ' Free memory when done
339
- ```
340
-
341
- **Use FastTrig when:** raycasting, rotating sprites, particle systems, any loop calling trig hundreds of times per frame.
342
- **Use regular SIN/COS when:** high precision needed, one-time calculations.
343
-
344
- ---
345
-
346
- ## String Functions
347
-
348
- | Function | Description |
349
- |----------|-------------|
350
- | `ASC(s$)` | Character to ASCII code |
351
- | `CHR(n)` | ASCII code to character |
352
- | `INSTR(s$, search$)` | Find substring position (0 = not found) |
353
- | `INSTR(start$, s$, search$)` | Find substring starting from position start$ (0 = not found) |
354
- | `INVERT(s$)` | Inverts a string |
355
- | `LCASE(s$)` | Converts to lowercase |
356
- | `LEFT(s$, n)` | First n characters |
357
- | `LEN(s$)` | String length |
358
- | `LTRIM(s$)` | Left trim |
359
- | `MID(s$, start, len)` | Substring (1-based) len optional |
360
- | `REPEAT(s$, n)` | Repeat s$ for n times |
361
- | `REPLACE(s$, old$, new$)` | Replace all occurrences |
362
- | `RIGHT(s$, n)` | Last n characters |
363
- | `RTRIM(s$)` | Right trim |
364
- | `SPLIT(s$, delim$, arr$)` | Split into array |
365
- | `SRAND(n)` | Returns random string length of n from allowed chars (letters, numbers and "_") |
366
- | `STR(n)` | Number to string |
367
- | `TRIM(s$)` | Remove leading/trailing spaces |
368
- | `UCASE(s$)` | Converts to uppercase |
369
- | `VAL(s$)` | String to number |
370
-
371
- ---
372
-
373
- ## File I/O
374
-
375
- ```basic
376
- ' Simple text file
377
- FileWrite "save.txt", data$
378
- LET data$ = FileRead("save.txt")
379
-
380
- ' Array read/write (key=value format)
381
- DIM a$
382
- a$("name") = "player1"
383
- a$("score") = 9999
384
- FileWrite "scores.txt", a$
385
-
386
- DIM b$
387
- LET b$ = FileRead("scores.txt")
388
- PRINT b$("name") ' Output: player1
389
- ```
390
-
391
- **Array file format:**
392
- ```
393
- name=player1
394
- score=9999
395
- multi,dim,key=value
396
- ```
397
-
398
- | Function/Command | Description |
399
- |---------|-------------|
400
- | `FileRead(path)` | Read file; returns string or populates array |
401
- | `FileWrite path, data` | Write string or array to file |
402
- | `FileExists(path)` | Returns 1 if file exists, 0 if not |
403
- | `FileDelete path` | Delete a file |
404
- | `FileList(path$, arr$)` | List files in directory into array |
405
-
406
- ---
407
-
408
- ## Network (HTTP)
409
-
410
- ```basic
411
- DIM response$
412
- LET response$ = HTTPGET("https://api.example.com/data")
413
- PRINT response$
414
-
415
- DIM result$
416
- LET result$ = HTTPPOST("https://api.example.com/post", "{""key"":""value""}")
417
- PRINT result$
418
- ```
419
-
420
- - Returns response body as string
421
- - Supports HTTPS
422
- - Use `""` inside strings to escape quotes in JSON bodies
423
- - Timeout handled gracefully — returns error message string on failure
424
-
425
- ---
426
-
427
- ## Sound (SDL2_mixer)
428
-
429
- ```basic
430
- DIM bgm$
431
- LET bgm$ = LOADSOUND("music.wav")
432
- LET sfx$ = LOADSOUND("jump.wav")
433
-
434
- SOUNDREPEAT(bgm$) ' Loop continuously
435
- SOUNDONCE(sfx$) ' Play once
436
- SOUNDSTOP(bgm$) ' Stop specific sound
437
- SOUNDSTOPALL ' Stop all sounds
438
- ```
439
-
440
- | Command | Description |
441
- |---------|-------------|
442
- | `LOADSOUND(path)` | Load sound file, returns ID |
443
- | `SOUNDONCE(id$)` | Play once |
444
- | `SOUNDREPEAT(id$)` | Loop continuously |
445
- | `SOUNDSTOP(id$)` | Stop specific sound |
446
- | `SOUNDSTOPALL` | Stop all sounds |
447
-
448
- - Formats: WAV (recommended), MP3, others via SDL2_mixer
449
- - Thread-safe, multiple simultaneous sounds supported
450
- - Load sounds once at startup for performance
451
-
452
- ---
453
-
454
- ## Graphics (SDL2)
455
-
456
- ### Screen Setup
457
- ```basic
458
- SCREEN 12 ' 640x480 VGA mode
459
- SCREEN 0, 800, 600, "Title" ' Custom size with title
460
- ```
461
- Modes: 0=640x400, 1=320x200, 2=640x350, 7=320x200, 9=640x350, 12=640x480, 13=320x200
462
-
463
- ### Fullscreen
464
- ```basic
465
- FULLSCREEN TRUE ' Borderless fullscreen
466
- FULLSCREEN FALSE ' Windowed mode
467
- ```
468
- Call after `SCREEN`.
469
-
470
- ### VSync
471
- ```basic
472
- VSYNC(TRUE) ' Enable (default) — caps to monitor refresh
473
- VSYNC(FALSE) ' Disable — unlimited FPS, may tear
474
- ```
475
-
476
- ### Double Buffering (Required for Animation)
477
- ```basic
478
- SCREENLOCK ON ' Start buffering
479
- ' ... draw commands ...
480
- SCREENLOCK OFF ' Display frame
481
- SLEEP 16 ' ~60 FPS
482
- ```
483
- `SCREENLOCK` without argument = `SCREENLOCK ON`. Do math/logic outside SCREENLOCK block.
484
-
485
- ### Drawing Primitives
486
- | Command | Description |
487
- |---------|-------------|
488
- | `PSET (x, y), color` | Draw pixel |
489
- | `POINT(x, y)` | Read pixel color (returns RGB integer) |
490
- | `LINE (x1,y1)-(x2,y2), color` | Draw line |
491
- | `LINE (x1,y1)-(x2,y2), color, B` | Box outline |
492
- | `LINE (x1,y1)-(x2,y2), color, BF` | Filled box (faster than CLS) |
493
- | `CIRCLE (cx, cy), r, color` | Circle outline |
494
- | `CIRCLE (cx, cy), r, color, 1` | Filled circle |
495
- | `PAINT (x, y), fill, border` | Flood fill |
496
- | `RGB(r, g, b)` | Create color (0-255 each) |
497
-
498
- ### Shape/Sprite System
499
- ```basic
500
- DIM sprite$
501
- sprite$ = LOADSHAPE("RECTANGLE", 50, 50, RGB(255,0,0)) ' Types: RECTANGLE, CIRCLE, TRIANGLE
502
- sprite$ = LOADIMAGE("player.png") ' PNG (with alpha) or BMP
503
-
504
- MOVESHAPE sprite$, x, y ' Position (top-left point)
505
- ROTATESHAPE sprite$, angle ' Absolute degrees
506
- SCALESHAPE sprite$, 1.5 ' 1.0 = original
507
- SHOWSHAPE sprite$
508
- HIDESHAPE sprite$
509
- DRAWSHAPE sprite$ ' Render
510
- REMOVESHAPE sprite$ ' Free memory
511
- ```
512
- - PNG recommended (full alpha transparency 0-255), BMP for legacy
513
- - Images positioned by their **top-left point**
514
- - Rotation is absolute, not cumulative
515
- - Always REMOVESHAPE when done to free memory
516
-
517
- ### Sprite Sheets (LOADSHEET)
518
- ```basic
519
- DIM sprites$
520
- LOADSHEET sprites$, spriteW, spriteH, "sheet.png"
521
-
522
- ' Access sprites by 1-based index
523
- MOVESHAPE sprites$(index$), x#, y#
524
- DRAWSHAPE sprites$(index$)
525
- ```
526
- - Sprites indexed left-to-right, top-to-bottom starting at 1
527
- - All sprites must be same size (spriteW x spriteH)
528
-
529
- ### Mouse Input (Graphics Mode Only)
530
- | Function | Description |
531
- |----------|-------------|
532
- | `MOUSEX` / `MOUSEY` | Cursor position |
533
- | `MOUSEB` | Button state (bitmask, use `AND`) |
534
-
535
- Button constants: `MOUSE_LEFT#`=1, `MOUSE_RIGHT#`=2, `MOUSE_MIDDLE#`=4
536
-
537
- ### Color Palette (0-15)
538
- | 0 Black | 4 Red | 8 Dark Gray | 12 Light Red |
539
- |---------|-------|-------------|--------------|
540
- | 1 Blue | 5 Magenta | 9 Light Blue | 13 Light Magenta |
541
- | 2 Green | 6 Brown | 10 Light Green | 14 Yellow |
542
- | 3 Cyan | 7 Light Gray | 11 Light Cyan | 15 White |
543
-
544
- ### Performance Tips
545
- 1. Use `SCREENLOCK ON/OFF` for all animation
546
- 2. `LINE...BF` is faster than `CLS` for clearing
547
- 3. Store `RGB()` values in constants
548
- 4. REMOVESHAPE unused shapes
549
- 5. SLEEP 16 for ~60 FPS
550
- 6. Do math/logic outside SCREENLOCK block
551
-
552
- ---
553
-
554
- ## Built-in Constants
555
-
556
- ### Arrow Keys
557
- | | | |
558
- |---|---|---|
559
- | `KEY_UP#` | `KEY_DOWN#` | `KEY_LEFT#` |
560
- | `KEY_RIGHT#` | | |
561
-
562
- ### Special Keys
563
- | | | |
564
- |---|---|---|
565
- | `KEY_ESC#` | `KEY_TAB#` | `KEY_BACKSPACE#` |
566
- | `KEY_ENTER#` | `KEY_SPACE#` | `KEY_INSERT#` |
567
- | `KEY_DELETE#` | `KEY_HOME#` | `KEY_END#` |
568
- | `KEY_PGUP#` | `KEY_PGDN#` | |
569
-
570
- ### Modifier Keys
571
- | | | |
572
- |---|---|---|
573
- | `KEY_LSHIFT#` | `KEY_RSHIFT#` | `KEY_LCTRL#` |
574
- | `KEY_RCTRL#` | `KEY_LALT#` | `KEY_RALT#` |
575
- | `KEY_LWIN#` | `KEY_RWIN#` | |
576
-
577
- ### Function Keys
578
- | | | |
579
- |---|---|---|
580
- | `KEY_F1#` | `KEY_F2#` | `KEY_F3#` |
581
- | `KEY_F4#` | `KEY_F5#` | `KEY_F6#` |
582
- | `KEY_F7#` | `KEY_F8#` | `KEY_F9#` |
583
- | `KEY_F10#` | `KEY_F11#` | `KEY_F12#` |
584
-
585
- ### Numpad Keys
586
- | | | |
587
- |---|---|---|
588
- | `KEY_NUMPAD0#` | `KEY_NUMPAD1#` | `KEY_NUMPAD2#` |
589
- | `KEY_NUMPAD3#` | `KEY_NUMPAD4#` | `KEY_NUMPAD5#` |
590
- | `KEY_NUMPAD6#` | `KEY_NUMPAD7#` | `KEY_NUMPAD8#` |
591
- | `KEY_NUMPAD9#` | | |
592
-
593
- ### Punctuation Keys
594
- | | | |
595
- |---|---|---|
596
- | `KEY_COMMA#` | `KEY_DOT#` | `KEY_MINUS#` |
597
- | `KEY_EQUALS#` | `KEY_SLASH#` | `KEY_BACKSLASH#` |
598
- | `KEY_SEP#` | `KEY_GRAVE#` | `KEY_LBRACKET#` |
599
- | `KEY_RBRACKET#` | | |
600
-
601
- ### Alphabet Keys
602
- | | | |
603
- |---|---|---|
604
- | `KEY_A#` | `KEY_B#` | `KEY_C#` |
605
- | `KEY_D#` | `KEY_E#` | `KEY_F#` |
606
- | `KEY_G#` | `KEY_H#` | `KEY_I#` |
607
- | `KEY_J#` | `KEY_K#` | `KEY_L#` |
608
- | `KEY_M#` | `KEY_N#` | `KEY_O#` |
609
- | `KEY_P#` | `KEY_Q#` | `KEY_R#` |
610
- | `KEY_S#` | `KEY_T#` | `KEY_U#` |
611
- | `KEY_V#` | `KEY_W#` | `KEY_X#` |
612
- | `KEY_Y#` | `KEY_Z#` | |
613
-
614
- ### Number Keys
615
- | | | |
616
- |---|---|---|
617
- | `KEY_0#` | `KEY_1#` | `KEY_2#` |
618
- | `KEY_3#` | `KEY_4#` | `KEY_5#` |
619
- | `KEY_6#` | `KEY_7#` | `KEY_8#` |
620
- | `KEY_9#` | | |
621
-
622
- ### Mouse
623
- ```basic
624
- MOUSE_LEFT# = 1, MOUSE_RIGHT# = 2, MOUSE_MIDDLE# = 4
625
- ```
626
-
627
- ### Logical
628
- `TRUE` = 1, `FALSE` = 0
629
-
630
- ---
631
-
632
- ## Source Control
633
-
634
- ### INCLUDE
635
- ```basic
636
- INCLUDE "other_file.bas" ' Insert source at this point
637
- INCLUDE "MathLib.bb" ' Include compiled library
638
- ```
639
-
640
- ### Libraries (.bb files)
641
- ```basic
642
- ' MathLib.bas — can ONLY contain DEF FN functions
643
- DEF FN add$(x$, y$)
644
- RETURN x$ + y$
645
- END DEF
646
- ```
647
- Compile: `bazzbasic.exe -lib MathLib.bas` → `MathLib.bb`
648
-
649
- ```basic
650
- INCLUDE "MathLib.bb"
651
- PRINT FN MATHLIB_add$(5, 3) ' Auto-prefix: FILENAME_ + functionName
652
- ```
653
- - Libraries can only contain `DEF FN` functions
654
- - Library functions can access main program constants (`#`)
655
- - Version-locked: .bb may not work across BazzBasic versions
656
-
657
- ---
658
-
659
- ## Common Patterns
660
-
661
- ### Game Loop
662
- ```basic
663
- SCREEN 12
664
- LET running$ = TRUE
665
-
666
- WHILE running$
667
- LET key$ = INKEY
668
- IF key$ = KEY_ESC# THEN running$ = FALSE
669
-
670
- ' Math and logic here
671
-
672
- SCREENLOCK ON
673
- LINE (0,0)-(640,480), 0, BF ' Fast clear
674
- ' Draw game state
675
- SCREENLOCK OFF
676
- SLEEP 16
677
- WEND
678
- END
679
- ```
680
-
681
- ### HTTP + Data
682
- ```basic
683
- DIM response$
684
- LET response$ = HTTPGET("https://api.example.com/scores")
685
- PRINT response$
686
-
687
- DIM payload$
688
- LET payload$ = HTTPPOST("https://api.example.com/submit", "{""score"":9999}")
689
- PRINT payload$
690
- ```
691
-
692
- ### Save/Load with Arrays
693
- ```basic
694
- DIM save$
695
- save$("level") = 3
696
- save$("hp") = 80
697
- FileWrite "save.txt", save$
698
-
699
- DIM load$
700
- LET load$ = FileRead("save.txt")
701
- PRINT load$("level") ' Output: 3
702
- ```
703
-
704
- ### Sound with Graphics
705
- ```basic
706
- SCREEN 12
707
- LET bgm$ = LOADSOUND("music.wav")
708
- LET sfx$ = LOADSOUND("jump.wav")
709
- SOUNDREPEAT(bgm$)
710
-
711
- WHILE INKEY <> KEY_ESC#
712
- IF INKEY = KEY_SPACE# THEN SOUNDONCE(sfx$)
713
- SLEEP 16
714
- WEND
715
- SOUNDSTOPALL
716
- END
717
- ```
718
-
719
- ---
720
-
721
- ## Code Style Conventions
722
-
723
- **Variables** — `camelCase$`
724
- ```basic
725
- LET playerName$ = "Hero"
726
- LET score$ = 0
727
- ```
728
-
729
- **Constants** — `UPPER_SNAKE_CASE#`
730
- ```basic
731
- LET MAX_HEALTH# = 100
732
- LET SCREEN_W# = 640
733
- ```
734
-
735
- **Arrays** — `camelCase$` (like variables, declared with DIM)
736
- ```basic
737
- DIM scores$
738
- DIM playerData$
739
- ```
740
-
741
- **User-defined functions** — `PascalCase$`
742
- ```basic
743
- DEF FN CalculateDamage$(attack$, defence$)
744
- DEF FN IsColliding$(x$, y$)
745
- ```
746
-
747
- **Labels** — descriptive names, `[sub:]` prefix recommended for subroutines
748
- ```basic
749
- [sub:DrawPlayer] ' Subroutine
750
- [gameLoop] ' Jump target
751
- ```
752
-
753
- ### Program Structure
754
- 1. Constants first
755
- 2. User-defined functions (or INCLUDE them)
756
- 3. Main program loop
757
- 4. Subroutines (labels) last
758
-
759
- ### Subroutine Indentation
760
- ```basic
761
- [sub:DrawPlayer]
762
- MOVESHAPE player$, x$, y$
763
- DRAWSHAPE player$
764
- RETURN
765
- ```