EkBass commited on
Commit
e94c148
·
verified ·
1 Parent(s): d46362a

Delete BazzBasic-AI-guide.md

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