EkBass commited on
Commit
9c5439a
·
verified ·
1 Parent(s): 8fe673d

Delete BazzBasic-AI-guide-21032026d.md

Browse files
Files changed (1) hide show
  1. BazzBasic-AI-guide-21032026d.md +0 -1070
BazzBasic-AI-guide-21032026d.md DELETED
@@ -1,1070 +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.1 and is updated 23.03.2026 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
- | `SHELL(cmd$)` | Run system command, returns output. Default 5000ms timeout |
432
- | `SHELL(cmd$, timeout$)` | Run system command with custom timeout in milliseconds |
433
-
434
- ---
435
-
436
- ## Network (HTTP)
437
-
438
- ```basic
439
- DIM response$
440
- LET response$ = HTTPGET("https://api.example.com/data")
441
- PRINT response$
442
-
443
- DIM result$
444
- LET result$ = HTTPPOST("https://api.example.com/post", "{""key"":""value""}")
445
- PRINT result$
446
- ```
447
-
448
- - Returns response body as string
449
- - Supports HTTPS
450
- - Use `""` inside strings to escape quotes in JSON bodies
451
- - Timeout handled gracefully — returns error message string on failure
452
-
453
- ### Encoding & Hashing
454
-
455
- | Function | Description |
456
- |----------|-------------|
457
- | `BASE64ENCODE(s$)` | Encode string to Base64 |
458
- | `BASE64DECODE(s$)` | Decode Base64 string |
459
- | `SHA256(s$)` | Returns lowercase hex SHA256 hash |
460
-
461
- ```vb
462
- LET encoded$ = BASE64ENCODE("Hello, World!")
463
- PRINT encoded$ ' SGVsbG8sIFdvcmxkIQ==
464
-
465
- LET decoded$ = BASE64DECODE(encoded$)
466
- PRINT decoded$ ' Hello, World!
467
-
468
- LET hash$ = SHA256("password123")
469
- PRINT hash$ ' ef92b778... (64-char lowercase hex)
470
- ```
471
-
472
- ### JSON
473
- BazzBasic arrays map naturally to JSON. Nested objects become comma-separated keys.
474
-
475
- ```vb
476
- DIM data$
477
- data$("name") = "Alice"
478
- data$("score") = 9999
479
- data$("address,city") = "New York"
480
- data$("skills,0") = "JavaScript"
481
- data$("skills,1") = "Python"
482
-
483
- LET json$ = ASJSON(data$)
484
- ' Output: {"name":"Alice","score":9999,"address":{"city":"New York"},"skills":["JavaScript","Python"]}
485
-
486
- DIM back$
487
- LET count$ = ASARRAY(back$, json$)
488
- PRINT back$("name") ' Output: Alice
489
- PRINT back$("address,city") ' Output: New York
490
- PRINT back$("skills,0") ' Output: JavaScript
491
-
492
- SAVEJSON data$, "scores.json"
493
- DIM loaded$
494
- LOADJSON loaded$, "scores.json"
495
- ```
496
-
497
- | Function | Description |
498
- |----------|-------------|
499
- | `ASJSON(arr$)` | Convert array to JSON string |
500
- | `ASARRAY(arr$, json$)` | Fill array from JSON string, returns element count |
501
- | `LOADJSON arr$, path$` | Load JSON file into array |
502
- | `SAVEJSON arr$, path$` | Save array as formatted JSON file |
503
-
504
- **Nested JSON key convention:** `object,key` and `array,index` (0-based)
505
-
506
- ---
507
-
508
- ## Sound (SDL2_mixer)
509
-
510
- ```basic
511
- DIM bgm$
512
- LET bgm$ = LOADSOUND("music.wav")
513
- LET sfx$ = LOADSOUND("jump.wav")
514
-
515
- SOUNDREPEAT(bgm$) ' Loop continuously
516
- SOUNDONCE(sfx$) ' Play once
517
- SOUNDSTOP(bgm$) ' Stop specific sound
518
- SOUNDSTOPALL ' Stop all sounds
519
- ```
520
-
521
- | Command | Description |
522
- |---------|-------------|
523
- | `LOADSOUND(path)` | Load sound file, returns ID |
524
- | `SOUNDONCE(id$)` | Play once |
525
- | `SOUNDREPEAT(id$)` | Loop continuously |
526
- | `SOUNDSTOP(id$)` | Stop specific sound |
527
- | `SOUNDSTOPALL` | Stop all sounds |
528
-
529
- - Formats: WAV (recommended), MP3, others via SDL2_mixer
530
- - Thread-safe, multiple simultaneous sounds supported
531
- - Load sounds once at startup for performance
532
-
533
- ---
534
-
535
- ## Graphics (SDL2)
536
-
537
- ### Screen Setup
538
- ```basic
539
- SCREEN 12 ' 640x480 VGA mode
540
- SCREEN 0, 800, 600, "Title" ' Custom size with title
541
- ```
542
- Modes: 0=640x400, 1=320x200, 2=640x350, 7=320x200, 9=640x350, 12=640x480, 13=320x200
543
-
544
- ### Fullscreen
545
- ```basic
546
- FULLSCREEN TRUE ' Borderless fullscreen
547
- FULLSCREEN FALSE ' Windowed mode
548
- ```
549
- Call after `SCREEN`.
550
-
551
- ### VSync
552
- ```basic
553
- VSYNC(TRUE) ' Enable (default) — caps to monitor refresh
554
- VSYNC(FALSE) ' Disable — unlimited FPS, may tear
555
- ```
556
-
557
- ### Double Buffering (Required for Animation)
558
- ```basic
559
- SCREENLOCK ON ' Start buffering
560
- ' ... draw commands ...
561
- SCREENLOCK OFF ' Display frame
562
- SLEEP 16 ' ~60 FPS
563
- ```
564
- `SCREENLOCK` without argument = `SCREENLOCK ON`. Do math/logic outside SCREENLOCK block.
565
-
566
- ### Drawing Primitives
567
- | Command | Description |
568
- |---------|-------------|
569
- | `PSET (x, y), color` | Draw pixel |
570
- | `POINT(x, y)` | Read pixel color (returns RGB integer) |
571
- | `LINE (x1,y1)-(x2,y2), color` | Draw line |
572
- | `LINE (x1,y1)-(x2,y2), color, B` | Box outline |
573
- | `LINE (x1,y1)-(x2,y2), color, BF` | Filled box (faster than CLS) |
574
- | `CIRCLE (cx, cy), r, color` | Circle outline |
575
- | `CIRCLE (cx, cy), r, color, 1` | Filled circle |
576
- | `PAINT (x, y), fill, border` | Flood fill |
577
- | `RGB(r, g, b)` | Create color (0-255 each) |
578
-
579
- ### Shape/Sprite System
580
- ```basic
581
- DIM sprite$
582
- sprite$ = LOADSHAPE("RECTANGLE", 50, 50, RGB(255,0,0)) ' Types: RECTANGLE, CIRCLE, TRIANGLE
583
- sprite$ = LOADIMAGE("player.png") ' PNG (with alpha) or BMP
584
-
585
- MOVESHAPE sprite$, x, y ' Position (top-left point)
586
- ROTATESHAPE sprite$, angle ' Absolute degrees
587
- SCALESHAPE sprite$, 1.5 ' 1.0 = original
588
- SHOWSHAPE sprite$
589
- HIDESHAPE sprite$
590
- DRAWSHAPE sprite$ ' Render
591
- REMOVESHAPE sprite$ ' Free memory
592
- ```
593
- - PNG recommended (full alpha transparency 0-255), BMP for legacy
594
- - Images positioned by their **top-left point**
595
- - Rotation is absolute, not cumulative
596
- - Always REMOVESHAPE when done to free memory
597
-
598
- ### LOADIMAGE with url
599
- ```vb
600
- LET sprite$ = LOADIMAGE("https://example.com/sprite.png")
601
- ' → downloads "sprite.png" to root of your program
602
- ' → sprite$ works just as with normal file load
603
-
604
- ' to remove or move the downloaded file
605
- SHELL("move sprite.png images\sprite.png") ' move to subfolder
606
- ' or
607
- FileDelete "sprite.png" ' just delete it
608
- ```
609
-
610
- ### Sprite Sheets (LOADSHEET)
611
- ```basic
612
- DIM sprites$
613
- LOADSHEET sprites$, spriteW, spriteH, "sheet.png"
614
-
615
- ' Access sprites by 1-based index
616
- MOVESHAPE sprites$(index$), x#, y#
617
- DRAWSHAPE sprites$(index$)
618
- ```
619
- - Sprites indexed left-to-right, top-to-bottom starting at 1
620
- - All sprites must be same size (spriteW x spriteH)
621
-
622
- ### Mouse Input (Graphics Mode Only)
623
- | Function | Description |
624
- |----------|-------------|
625
- | `MOUSEX` / `MOUSEY` | Cursor position |
626
- | `MOUSEB` | Button state (bitmask, use `AND`) |
627
-
628
- Button constants: `MOUSE_LEFT#`=1, `MOUSE_RIGHT#`=2, `MOUSE_MIDDLE#`=4
629
-
630
- ### Color Palette (0-15)
631
- | 0 Black | 4 Red | 8 Dark Gray | 12 Light Red |
632
- |---------|-------|-------------|--------------|
633
- | 1 Blue | 5 Magenta | 9 Light Blue | 13 Light Magenta |
634
- | 2 Green | 6 Brown | 10 Light Green | 14 Yellow |
635
- | 3 Cyan | 7 Light Gray | 11 Light Cyan | 15 White |
636
-
637
- ### Performance Tips
638
- 1. Use `SCREENLOCK ON/OFF` for all animation
639
- 2. `LINE...BF` is faster than `CLS` for clearing
640
- 3. Store `RGB()` values in constants
641
- 4. REMOVESHAPE unused shapes
642
- 5. SLEEP 16 for ~60 FPS
643
- 6. Do math/logic outside SCREENLOCK block
644
-
645
- ---
646
-
647
- ## Built-in Constants
648
-
649
- ### Arrow Keys
650
- | | | |
651
- |---|---|---|
652
- | `KEY_UP#` | `KEY_DOWN#` | `KEY_LEFT#` |
653
- | `KEY_RIGHT#` | | |
654
-
655
- ### Special Keys
656
- | | | |
657
- |---|---|---|
658
- | `KEY_ESC#` | `KEY_TAB#` | `KEY_BACKSPACE#` |
659
- | `KEY_ENTER#` | `KEY_SPACE#` | `KEY_INSERT#` |
660
- | `KEY_DELETE#` | `KEY_HOME#` | `KEY_END#` |
661
- | `KEY_PGUP#` | `KEY_PGDN#` | |
662
-
663
- ### Modifier Keys
664
- | | | |
665
- |---|---|---|
666
- | `KEY_LSHIFT#` | `KEY_RSHIFT#` | `KEY_LCTRL#` |
667
- | `KEY_RCTRL#` | `KEY_LALT#` | `KEY_RALT#` |
668
- | `KEY_LWIN#` | `KEY_RWIN#` | |
669
-
670
- ### Function Keys
671
- | | | |
672
- |---|---|---|
673
- | `KEY_F1#` | `KEY_F2#` | `KEY_F3#` |
674
- | `KEY_F4#` | `KEY_F5#` | `KEY_F6#` |
675
- | `KEY_F7#` | `KEY_F8#` | `KEY_F9#` |
676
- | `KEY_F10#` | `KEY_F11#` | `KEY_F12#` |
677
-
678
- ### Numpad Keys
679
- | | | |
680
- |---|---|---|
681
- | `KEY_NUMPAD0#` | `KEY_NUMPAD1#` | `KEY_NUMPAD2#` |
682
- | `KEY_NUMPAD3#` | `KEY_NUMPAD4#` | `KEY_NUMPAD5#` |
683
- | `KEY_NUMPAD6#` | `KEY_NUMPAD7#` | `KEY_NUMPAD8#` |
684
- | `KEY_NUMPAD9#` | | |
685
-
686
- ### Punctuation Keys
687
- | | | |
688
- |---|---|---|
689
- | `KEY_COMMA#` | `KEY_DOT#` | `KEY_MINUS#` |
690
- | `KEY_EQUALS#` | `KEY_SLASH#` | `KEY_BACKSLASH#` |
691
- | `KEY_SEP#` | `KEY_GRAVE#` | `KEY_LBRACKET#` |
692
- | `KEY_RBRACKET#` | | |
693
-
694
- ### Alphabet Keys
695
- | | | |
696
- |---|---|---|
697
- | `KEY_A#` | `KEY_B#` | `KEY_C#` |
698
- | `KEY_D#` | `KEY_E#` | `KEY_F#` |
699
- | `KEY_G#` | `KEY_H#` | `KEY_I#` |
700
- | `KEY_J#` | `KEY_K#` | `KEY_L#` |
701
- | `KEY_M#` | `KEY_N#` | `KEY_O#` |
702
- | `KEY_P#` | `KEY_Q#` | `KEY_R#` |
703
- | `KEY_S#` | `KEY_T#` | `KEY_U#` |
704
- | `KEY_V#` | `KEY_W#` | `KEY_X#` |
705
- | `KEY_Y#` | `KEY_Z#` | |
706
-
707
- ### Number Keys
708
- | | | |
709
- |---|---|---|
710
- | `KEY_0#` | `KEY_1#` | `KEY_2#` |
711
- | `KEY_3#` | `KEY_4#` | `KEY_5#` |
712
- | `KEY_6#` | `KEY_7#` | `KEY_8#` |
713
- | `KEY_9#` | | |
714
-
715
- ### Mouse
716
- ```basic
717
- MOUSE_LEFT# = 1, MOUSE_RIGHT# = 2, MOUSE_MIDDLE# = 4
718
- ```
719
-
720
- ### Logical
721
- `TRUE` = 1, `FALSE` = 0
722
-
723
- ---
724
-
725
- ## TIME & TICKS
726
-
727
- ### TIME(format$)
728
- Returns current date/time as a formatted string. Uses .NET DateTime format strings.
729
- ```vb
730
- PRINT TIME() ' Default: "16:30:45"
731
- PRINT TIME("HH:mm:ss") ' "16:30:45"
732
- PRINT TIME("dd.MM.yyyy") ' "09.01.2026"
733
- PRINT TIME("yyyy-MM-dd") ' "2026-01-09"
734
- PRINT TIME("dddd") ' "Friday"
735
- PRINT TIME("MMMM") ' "January"
736
- PRINT TIME("dd MMMM yyyy") ' "09 January 2026"
737
- PRINT TIME("HH:mm") ' "16:30"
738
- ```
739
-
740
- **Common format codes:**
741
- | Code | Description | Example |
742
- |------|-------------|--------|
743
- | HH | Hour (00-23) | 16 |
744
- | mm | Minutes | 30 |
745
- | ss | Seconds | 45 |
746
- | dd | Day | 09 |
747
- | MM | Month (number) | 01 |
748
- | MMM | Month (short) | Jan |
749
- | MMMM | Month (full) | January |
750
- | yy | Year (2 digits) | 26 |
751
- | yyyy | Year (4 digits) | 2026 |
752
- | ddd | Weekday (short) | Fri |
753
- | dddd | Weekday (full) | Friday |
754
-
755
-
756
- ### TICKS
757
- Returns milliseconds elapsed since program started. Useful for timing, animations, and game loops.
758
- ```vb
759
- LET start$ = TICKS
760
-
761
- ' Do some work
762
- FOR i$ = 1 TO 10000
763
- LET x$ = x$ + 1
764
- NEXT
765
-
766
- LET elapsed$ = TICKS - start$
767
- PRINT "Time taken: "; elapsed$; " ms"
768
- ```
769
- ## Source Control
770
-
771
- ### INCLUDE
772
- ```basic
773
- INCLUDE "other_file.bas" ' Insert source at this point
774
- INCLUDE "MathLib.bb" ' Include compiled library
775
- ```
776
-
777
- ### Libraries (.bb files)
778
- ```basic
779
- ' MathLib.bas — can ONLY contain DEF FN functions
780
- DEF FN add$(x$, y$)
781
- RETURN x$ + y$
782
- END DEF
783
- ```
784
- Compile: `bazzbasic.exe -lib MathLib.bas` → `MathLib.bb`
785
-
786
- ```basic
787
- INCLUDE "MathLib.bb"
788
- PRINT FN MATHLIB_add$(5, 3) ' Auto-prefix: FILENAME_ + functionName
789
- ```
790
- - Libraries can only contain `DEF FN` functions
791
- - Library functions can access main program constants (`#`)
792
- - Version-locked: .bb may not work across BazzBasic versions
793
-
794
- ---
795
-
796
- ## Common Patterns
797
-
798
- ### Game Loop
799
- ```basic
800
- SCREEN 12
801
- LET running$ = TRUE
802
-
803
- WHILE running$
804
- LET key$ = INKEY
805
- IF key$ = KEY_ESC# THEN running$ = FALSE
806
-
807
- ' Math and logic here
808
-
809
- SCREENLOCK ON
810
- LINE (0,0)-(640,480), 0, BF ' Fast clear
811
- ' Draw game state
812
- SCREENLOCK OFF
813
- SLEEP 16
814
- WEND
815
- END
816
- ```
817
-
818
- ### HTTP + Data
819
- ```basic
820
- DIM response$
821
- LET response$ = HTTPGET("https://api.example.com/scores")
822
- PRINT response$
823
-
824
- DIM payload$
825
- LET payload$ = HTTPPOST("https://api.example.com/submit", "{""score"":9999}")
826
- PRINT payload$
827
- ```
828
-
829
- ### Save/Load with Arrays
830
- ```basic
831
- DIM save$
832
- save$("level") = 3
833
- save$("hp") = 80
834
- FileWrite "save.txt", save$
835
-
836
- DIM load$
837
- LET load$ = FileRead("save.txt")
838
- PRINT load$("level") ' Output: 3
839
- ```
840
-
841
- ## Arrays and JSON
842
-
843
- BazzBasic arrays map naturally to JSON. Nested JSON objects and arrays become multi-dimensional keys using comma-separated indices.
844
-
845
- ### ASJSON
846
- Converts a BazzBasic array to a JSON string:
847
- ```vb
848
- DIM player$
849
- player$("name") = "Alice"
850
- player$("score") = 9999
851
- player$("address,city") = "New York"
852
- player$("skills,0") = "JavaScript"
853
- player$("skills,1") = "Python"
854
-
855
- LET json$ = ASJSON(player$)
856
- PRINT json$
857
- ' Output: {"name":"Alice","score":9999,"address":{"city":"New York"},"skills":["JavaScript","Python"]}
858
- ```
859
-
860
- ### ASARRAY
861
- Converts a JSON string into a BazzBasic array. Returns number of elements loaded:
862
- ```vb
863
- DIM data$
864
- LET count$ = ASARRAY(data$, "{""name"":""Bob"",""score"":42}")
865
-
866
- PRINT data$("name") ' Output: Bob
867
- PRINT data$("score") ' Output: 42
868
- PRINT count$ ' Output: 2
869
- ```
870
-
871
- Nested JSON becomes comma-separated keys:
872
- ```vb
873
- DIM data$
874
- LET json$ = "{""player"":{""name"":""Alice"",""hp"":100},""skills"":[""fire"",""ice""]}"
875
- ASARRAY data$, json$
876
-
877
- PRINT data$("player,name") ' Output: Alice
878
- PRINT data$("player,hp") ' Output: 100
879
- PRINT data$("skills,0") ' Output: fire
880
- PRINT data$("skills,1") ' Output: ice
881
- ```
882
-
883
- ### LOADJSON
884
- Loads a JSON file directly into an array:
885
- ```vb
886
- DIM scores$
887
- LOADJSON scores$, "highscores.json"
888
-
889
- PRINT scores$("first,name") ' Output: depends on file contents
890
- ```
891
-
892
- ### SAVEJSON
893
- Saves an array as a formatted JSON file:
894
- ```vb
895
- DIM save$
896
- save$("level") = 3
897
- save$("hp") = 80
898
- save$("position,x") = 100
899
- save$("position,y") = 200
900
-
901
- SAVEJSON save$, "savegame.json"
902
- ```
903
-
904
- The resulting `savegame.json`:
905
- ```json
906
- {
907
- "level": 3,
908
- "hp": 80,
909
- "position": {
910
- "x": 100,
911
- "y": 200
912
- }
913
- }
914
- ```
915
-
916
- ### Practical example: HTTP API + JSON
917
- ```vb
918
- DIM response$
919
- LET raw$ = HTTPGET("https://api.example.com/user/1")
920
- ASARRAY response$, raw$
921
-
922
- PRINT "Name: "; response$("name")
923
- PRINT "Email: "; response$("email")
924
- ```
925
-
926
- ### Sound with Graphics
927
- ```basic
928
- SCREEN 12
929
- LET bgm$ = LOADSOUND("music.wav")
930
- LET sfx$ = LOADSOUND("jump.wav")
931
- SOUNDREPEAT(bgm$)
932
-
933
- WHILE INKEY <> KEY_ESC#
934
- IF INKEY = KEY_SPACE# THEN SOUNDONCE(sfx$)
935
- SLEEP 16
936
- WEND
937
- SOUNDSTOPALL
938
- END
939
- ```
940
-
941
- ---
942
-
943
- ## Code Style Conventions
944
-
945
- **Variables** — `camelCase$`
946
- ```basic
947
- LET playerName$ = "Hero"
948
- LET score$ = 0
949
- ```
950
-
951
- **Constants** — `UPPER_SNAKE_CASE#`
952
- ```basic
953
- LET MAX_HEALTH# = 100
954
- LET SCREEN_W# = 640
955
- ```
956
-
957
- **Arrays** — `camelCase$` (like variables, declared with DIM)
958
- ```basic
959
- DIM scores$
960
- DIM playerData$
961
- ```
962
-
963
- **User-defined functions** — `PascalCase$`
964
- ```basic
965
- DEF FN CalculateDamage$(attack$, defence$)
966
- DEF FN IsColliding$(x$, y$)
967
- ```
968
-
969
- **Labels** — descriptive names, `[sub:]` prefix recommended for subroutines
970
- ```basic
971
- [sub:DrawPlayer] ' Subroutine
972
- [gameLoop] ' Jump target
973
- ```
974
-
975
- ## Program Structure
976
-
977
- 1. Constants first
978
- 2. User-defined functions
979
- 3. Init
980
- 4. Main program loop
981
- 5. Subroutines (labels) last
982
-
983
- ```basic
984
- ' ── 1. CONSTANTS ────────────────────────────
985
- ' or INCLUDE as "constants.bas" etc
986
-
987
- LET SCREEN_W# = 640
988
- LET SCREEN_H# = 480
989
- LET MAX_SPEED# = 5
990
-
991
- ' ── 2. FUNCTIONS ────────────────────────────
992
- ' or INCLUDE as "functions.bas" etc
993
- DEF FN Clamp$(val$, lo$, hi$)
994
- IF val$ < lo$ THEN RETURN lo$
995
- IF val$ > hi$ THEN RETURN hi$
996
- RETURN val$
997
- END DEF
998
-
999
- ' ── 3. INIT ─────────────────────────────────
1000
- ' or INCLUDE as "inits.bas" etc
1001
- ' IMPORTANT:
1002
- ' Avoid declaring variables outside INIT if speed matters.
1003
- ' If done inside [main] or [subs], Bazzbasic has to check the existence of the variable in each call.
1004
-
1005
- [inits]
1006
- SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
1007
- LET x$ = 100
1008
- LET y$ = 100
1009
- LET running$ = TRUE
1010
-
1011
- ' ── 4. MAIN LOOP ───────────────────────���────
1012
- [main]
1013
- WHILE running$
1014
- IF INKEY = KEY_ESC# THEN running$ = FALSE
1015
- GOSUB [sub:update]
1016
- GOSUB [sub:draw]
1017
- SLEEP 16
1018
- WEND
1019
- END
1020
-
1021
- ' ── 5. SUBROUTINES ──────────────────────────
1022
- ' or INCLUDE as "subs.bas" etc
1023
-
1024
- [sub:update]
1025
- IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED#
1026
- IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED#
1027
- RETURN
1028
-
1029
- [sub:draw]
1030
- SCREENLOCK ON
1031
- LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
1032
- CIRCLE (x$, y$), 10, RGB(0,255,0), 1
1033
- SCREENLOCK OFF
1034
- RETURN
1035
- ```
1036
-
1037
- ### Images and sounds
1038
- When ever there is no reason to change the ID reference of image/sound, we should use constants.
1039
-
1040
- ```basic
1041
- LET MY_IMAGE# = LOADIMAGE("temp.bmp") ' Correct
1042
- LET myImage$# = LOADIMAGE("temp.bmp") ' Wrong
1043
- ```
1044
-
1045
- To change image of enemy during the game
1046
- ```basic
1047
- LET ENEMY1# = LOADIMAGE("enemy1.bmp")
1048
- LET ENEMY2# = LOADIMAGE("enemy2.bmp")
1049
-
1050
- ' begin of game
1051
- LET curEnemy$ = ENEMY1#
1052
-
1053
- ' after Enemy1 has died
1054
- curEnemy$ = ENEMY2#
1055
- ```
1056
-
1057
- ### Collect
1058
- Collect data of same types, characters etc. inside of array if amount of variables starts to pile up.
1059
-
1060
- ```basic
1061
- ' while this breaks the idea of making images constants, it helps by packing all images to same array
1062
- ' notice also how I intent even DIM
1063
- DIM enemyImages$
1064
- enemyImages$("enemy1") = LOADIMAGE("enemy1.bmp")
1065
- enemyImages$("enemy2") = LOADIMAGE("enemy2.bmp")
1066
-
1067
- DIM levelSprites$
1068
- levelSprites$("floor") = LOADIMAGE("floor.png")
1069
- levelSprites$("table") = LOADIMAGE("table.png")
1070
- ```