Update SKILL.md
Browse files
SKILL.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
name: bazzbasic-code
|
| 3 |
-
description: "BazzBasic BASIC interpreter language reference. Use when writing, debugging, or explaining BazzBasic code (.bas files). Triggers on BazzBasic syntax, $ and # variable suffixes, SDL2 graphics in BASIC, SCREEN/DRAWSHAPE/LOADIMAGE commands, DEF FN functions, BazzBasic file I/O, sound commands, or any question about BazzBasic features. Always use this skill before writing any BazzBasic code."
|
| 4 |
---
|
| 5 |
|
| 6 |
# BazzBasic Language Reference
|
| 7 |
-
**Version:** 1.6 | **Author:** Kristian Virtanen (EkBass) | **Platform:** Windows x64
|
| 8 |
**Homepage:** https://ekbass.github.io/BazzBasic/
|
| 9 |
**GitHub:** https://github.com/EkBass/BazzBasic
|
| 10 |
**Manual:** https://ekbass.github.io/BazzBasic/manual/#/
|
|
@@ -13,7 +13,8 @@ description: "BazzBasic BASIC interpreter language reference. Use when writing,
|
|
| 13 |
**Rosetta Code solutions:** https://github.com/EkBass/BazzBasic/tree/main/Examples/rosetta-code
|
| 14 |
**BazzBasic-AI-Guide:** https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
|
| 15 |
**BazzBasic Beginner's Guide:** https://github.com/EkBass/BazzBasic-Beginners-Guide/releases
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
---
|
| 19 |
|
|
@@ -21,22 +22,26 @@ description: "BazzBasic BASIC interpreter language reference. Use when writing,
|
|
| 21 |
|
| 22 |
| Rule | Detail |
|
| 23 |
|------|--------|
|
| 24 |
-
| Variables end with `$` | `name$`, `score$`, `x$` |
|
| 25 |
-
| Constants end with `#` | `MAX#`, `PI#`, `TITLE#` |
|
| 26 |
| Arrays declared with `DIM`, end with `$` | `DIM items$` |
|
| 27 |
| First use of variable requires `LET` | `LET x$ = 0` — after that `x$ = x$ + 1` |
|
| 28 |
| FOR and INPUT auto-declare, no LET needed | `FOR i$ = 1 TO 10` |
|
| 29 |
-
|
|
|
|
|
| 30 |
| Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
|
| 31 |
| Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
|
| 32 |
-
|
|
| 33 |
-
|
|
| 34 |
-
| `+` 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 |
|
| 35 |
| Division always returns float | `10 / 3` → `3.333...` |
|
| 36 |
-
| Division by zero returns `0`
|
| 37 |
| No integer-division operator | Use `INT(a / b)`, `FLOOR(a / b)`, or `CINT(a / b)` |
|
| 38 |
| Errors halt the program | No `TRY`/`CATCH` or `ON ERROR` — line-numbered message printed |
|
| 39 |
-
| No line-continuation char |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
---
|
| 42 |
|
|
@@ -53,79 +58,51 @@ DEF FN doStuff(a, b) DEF FN DoStuff$(a$, b$)
|
|
| 53 |
FN MyFunc$(5) ' return ignored LET v$ = FN MyFunc$(5)
|
| 54 |
LET handle$ = LOADIMAGE("x.png") LET HANDLE# = LOADIMAGE("x.png")
|
| 55 |
CLS ' in graphics mode LINE (0,0)-(W,H), 0, BF
|
| 56 |
-
PRINT "x:", x$ ' in graphics mode DRAWSTRING "x:" +
|
| 57 |
FSTRING("Hi {{name$}}") ' Python-style FSTRING("Hi {{-name$-}}") ' triple-char markers
|
| 58 |
ISSET(arr$(0)) ' expecting error ' returns 0 silently — ISSET only sees scalars
|
| 59 |
LET x$ = a$ + _ ' VBA continuation LET x$ = a$ + ' just leave the operator
|
| 60 |
-
LET x$ = a$ + \ ' Python continuation LET x$ = a$ + ' or open a paren
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
---
|
| 69 |
|
| 70 |
## Minimal Valid Program
|
| 71 |
|
| 72 |
```basic
|
| 73 |
-
'
|
| 74 |
-
[inits] ' [name] is a plain jump label, not a keyword — see Control Flow
|
| 75 |
LET name$ = "World"
|
| 76 |
|
| 77 |
[main]
|
| 78 |
PRINT "Hello, " + name$
|
| 79 |
END
|
| 80 |
|
| 81 |
-
'
|
| 82 |
[sub:drawScreen]
|
| 83 |
-
|
| 84 |
RETURN
|
| 85 |
```
|
| 86 |
|
| 87 |
-
Programs flow top to bottom. `[inits]` and `[main]` are organizational labels, not required syntax
|
| 88 |
-
|
| 89 |
-
---
|
| 90 |
-
|
| 91 |
-
## When Generating BazzBasic Code
|
| 92 |
-
|
| 93 |
-
(Suffix and return-value rules are already covered in Critical Rules above — not repeated here.)
|
| 94 |
-
|
| 95 |
-
- Prefer `FSTRING` over long `+` concatenation chains for multi-variable strings
|
| 96 |
-
- Place `DEF FN` definitions at the top of the file or via `INCLUDE`
|
| 97 |
-
- Store every `LOADIMAGE` / `LOADSOUND` / `LOADSHAPE` handle as a `#` constant
|
| 98 |
-
- In graphics mode, prefer `LINE (0,0)-(W,H), 0, BF` over `CLS`, and `DRAWSTRING` over `PRINT`
|
| 99 |
-
- Wrap each frame's drawing in `SCREENLOCK ON` / `SCREENLOCK OFF`
|
| 100 |
-
- 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
|
| 101 |
-
|
| 102 |
-
---
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
## ABOUT
|
| 106 |
-
|
| 107 |
-
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.
|
| 108 |
-
|
| 109 |
-
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.
|
| 110 |
-
|
| 111 |
-
To arouse your curiosity.
|
| 112 |
-
|
| 113 |
-
*EkBass*, author of BazzBasic
|
| 114 |
-
|
| 115 |
-
---
|
| 116 |
-
|
| 117 |
-
## Case sensitivity
|
| 118 |
-
BazzBasic is not case-sensitive except with string contents.
|
| 119 |
-
```basic
|
| 120 |
-
let blaa$ = "Hello"
|
| 121 |
-
PriNT BLAA$ ' output: Hello
|
| 122 |
-
```
|
| 123 |
|
| 124 |
---
|
| 125 |
|
| 126 |
## Line Continuation
|
| 127 |
|
| 128 |
-
|
| 129 |
|
| 130 |
**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:
|
| 131 |
|
|
@@ -144,8 +121,7 @@ LET counter$ +=
|
|
| 144 |
|
| 145 |
Tokens that trigger this: `+ - * / % = <> < <= > >= AND OR += -= *= /= ,`
|
| 146 |
|
| 147 |
-
> `%`
|
| 148 |
-
> `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).
|
| 149 |
|
| 150 |
**Rule 2 — open paren.** Anything inside an unmatched `(` keeps reading until the matching `)`:
|
| 151 |
|
|
@@ -156,115 +132,90 @@ LET dist$ = DISTANCE(
|
|
| 156 |
)
|
| 157 |
```
|
| 158 |
|
| 159 |
-
Both rules combine:
|
| 160 |
-
|
| 161 |
-
```basic
|
| 162 |
-
LET total$ = (
|
| 163 |
-
base$ +
|
| 164 |
-
tax$
|
| 165 |
-
)
|
| 166 |
-
```
|
| 167 |
-
|
| 168 |
-
**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.
|
| 169 |
-
|
| 170 |
---
|
| 171 |
|
| 172 |
## Variables & Constants
|
| 173 |
-
Variables and constants must be declared with LET before they can be used.
|
| 174 |
-
BazzBasic variables are not typed, but work the same way as in JavaScript, for example.
|
| 175 |
-
A variable needs the suffix $ which often is linked as STRING in traditional basic variants.
|
| 176 |
|
| 177 |
-
Variables
|
| 178 |
-
|
| 179 |
```basic
|
| 180 |
-
LET a$
|
| 181 |
-
LET b$, c$, d$
|
| 182 |
-
LET e$, f$ = "foo", g$ = 10
|
| 183 |
|
| 184 |
-
LET name$ = "Alice"
|
| 185 |
-
LET score$ = 0
|
| 186 |
|
| 187 |
-
LET PI# = 3.14159
|
| 188 |
-
LET TITLE# = "My Game"
|
| 189 |
```
|
| 190 |
|
| 191 |
-
**Compound assignment
|
| 192 |
|
| 193 |
```basic
|
| 194 |
LET x$ = 1
|
| 195 |
-
x$ += 5
|
| 196 |
-
x$ -= 3
|
| 197 |
-
x$ *= 2
|
| 198 |
-
x$ /= 4
|
| 199 |
LET s$ = "Hello"
|
| 200 |
-
s$ += " World" '
|
| 201 |
```
|
| 202 |
|
| 203 |
-
**Scope:** All main-code variables share one scope
|
| 204 |
-
Main-code variables ($) and arrays are NOT accessible inside DEF FN.
|
| 205 |
-
`DEF FN` functions are fully isolated — only global constants (`#`) accessible inside.
|
| 206 |
|
| 207 |
**Comparison:** `"123" = 123` is TRUE (cross-type), but keep types consistent for speed.
|
| 208 |
|
| 209 |
-
---
|
| 210 |
-
|
| 211 |
### Built-in Constants
|
| 212 |
-
- **Boolean:** `TRUE` (`1`), `FALSE` (`0`) — plain numbers
|
| 213 |
-
- **Math:** `PI#`, `HPI#` (π/2 = 90°), `QPI#` (π/4 = 45°), `TAU#` (2π = 360°), `EULER#` (e)
|
| 214 |
-
- **System:** `PRG_ROOT#` (program base directory path)
|
| 215 |
-
- **Version:** `BBVER#` (
|
| 216 |
-
- **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_NUMPAD0#`…`KEY_NUMPAD9#`, `KEY_NUMPAD_PLUS#`
|
| 217 |
-
- **Gamepad:**
|
| 218 |
|
| 219 |
---
|
| 220 |
|
| 221 |
## Arrays
|
| 222 |
-
BazzBasic arrays are fully dynamic and support numeric, string, or mixed indexing.
|
| 223 |
|
|
|
|
| 224 |
|
| 225 |
```basic
|
| 226 |
DIM scores$ ' Declare (required before use)
|
| 227 |
DIM a$, b$, c$ ' Multiple
|
| 228 |
-
scores$(0) = 95 ' Numeric indices are 0-based
|
| 229 |
-
scores$("name") = "Alice" ' String keys
|
| 230 |
matrix$(0, 1) = "A2" ' Multi-dimensional
|
| 231 |
|
| 232 |
DIM sounds$
|
| 233 |
-
sounds$("guns", "shotgun_shoot")
|
| 234 |
-
sounds$("guns", "
|
| 235 |
-
sounds$("
|
| 236 |
-
sounds$("guns", "ak47_reload") = "reload_ak47.wav"
|
| 237 |
-
sounds$("food", "ham_eat") = "eat_ham.wav"
|
| 238 |
|
| 239 |
-
PRINT LEN(sounds$()) '
|
| 240 |
-
PRINT ROWCOUNT(sounds$()) ' 2
|
| 241 |
|
| 242 |
DIM car$
|
| 243 |
car$("manufacturer") = "Ford"
|
| 244 |
car$("engine") = "1.6 Eco"
|
| 245 |
-
car$("color") = "Blue"
|
| 246 |
|
| 247 |
-
FOR i$ = 0 TO LEN(car$()) - 1 '
|
| 248 |
-
LET key$ = ARRKEY(car$(), i$)
|
| 249 |
PRINT key$; " = "; car$(key$)
|
| 250 |
NEXT i$
|
| 251 |
```
|
| 252 |
|
| 253 |
| Function/Command | Description |
|
| 254 |
|-----------------|-------------|
|
| 255 |
-
| `LEN(arr$())` | Total element count
|
| 256 |
| `ROWCOUNT(arr$())` | Count of first-dimension rows — use this for FOR loops over multi-dim arrays |
|
| 257 |
-
| `ARRKEY(arr$(), i)` | Key at 0-based index `i`, in insertion order.
|
| 258 |
-
| `HASKEY(arr$(key))` | 1 if exists, 0 if not |
|
| 259 |
| `DELKEY arr$(key)` | Remove one element |
|
| 260 |
| `DELARRAY arr$` | Remove entire array (can re-DIM after) |
|
| 261 |
-
| `JOIN dest$, src1$, src2$` | Merge two arrays; `src2$` keys overwrite `src1$`. Use empty `src1$`
|
| 262 |
-
|
| 263 |
-
**JOIN** Matching keys from src2$ overwrite src1$ at the same level
|
| 264 |
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
> `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`.
|
| 268 |
|
| 269 |
---
|
| 270 |
|
|
@@ -293,22 +244,10 @@ WHILE x$ < 100
|
|
| 293 |
x$ = x$ * 2
|
| 294 |
WEND
|
| 295 |
|
| 296 |
-
' Leave a loop early: EXIT WHILE / EXIT FOR (innermost loop of that kind)
|
| 297 |
-
WHILE 1
|
| 298 |
-
IF INKEY = KEY_ESC# THEN EXIT WHILE
|
| 299 |
-
WEND
|
| 300 |
-
FOR i$ = 1 TO 100
|
| 301 |
-
IF i$ * i$ > 50 THEN EXIT FOR ' i$ keeps its value (8)
|
| 302 |
-
NEXT
|
| 303 |
-
' Use EXIT, not GOTO, to leave a loop: GOTO leaves stale loop state behind.
|
| 304 |
-
' EXIT WHILE inside a FOR inside a WHILE leaves both. Inside DEF FN, EXIT only
|
| 305 |
-
' leaves loops inside the function. No EXIT DEF / EXIT GOSUB (use RETURN).
|
| 306 |
-
|
| 307 |
' Labels, GOTO, GOSUB
|
| 308 |
[start]
|
| 309 |
GOSUB [sub:init]
|
| 310 |
-
|
| 311 |
-
GOTO [start]
|
| 312 |
|
| 313 |
[sub:init]
|
| 314 |
LET x$ = 0
|
|
@@ -318,77 +257,59 @@ RETURN
|
|
| 318 |
LET target$ = "[menu]"
|
| 319 |
GOTO target$
|
| 320 |
|
| 321 |
-
' Other
|
| 322 |
SLEEP 2000 ' Pause for milliseconds
|
| 323 |
END ' Terminate program
|
| 324 |
```
|
| 325 |
-
|
| 326 |
-
Whitespace is trimmed
|
|
|
|
| 327 |
---
|
| 328 |
|
| 329 |
## I/O
|
| 330 |
|
| 331 |
| Command | Description |
|
| 332 |
|---------|-------------|
|
| 333 |
-
| `PRINT expr; expr` | `;` = no space, `,` = tab |
|
| 334 |
| `PRINT "text";` | Trailing `;` suppresses newline |
|
| 335 |
-
| `INPUT "prompt", var$` | Splits on whitespace/comma |
|
| 336 |
| `INPUT "prompt", a$, b$` | Multiple values |
|
| 337 |
| `LINE INPUT "prompt", var$` | Read entire line with spaces |
|
| 338 |
-
| `CLS` | Clear screen |
|
| 339 |
| `LOCATE row, col` | Move cursor (1-based) |
|
| 340 |
| `CURPOS("row")` / `CURPOS("col")` | Read cursor row or col (1-based, matches LOCATE) |
|
| 341 |
| `CURPOS()` | Read cursor as `"row,col"` string |
|
| 342 |
-
| `COLOR fg, bg` | Text colors
|
|
|
|
| 343 |
| `SHELL("cmd")` | Run shell command, returns output |
|
| 344 |
| `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
|
| 345 |
|
| 346 |
-
|
| 347 |
-
' , prints tab separation
|
| 348 |
-
' Both can be mixed in a single PRINT statement
|
| 349 |
-
' INPUT splits on whitespace and comma; quoted strings are treated as single values
|
| 350 |
|
| 351 |
-
**
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
- Always append `2>&1` to the command, or SQL errors disappear silently.
|
| 355 |
-
- Use `\"` (BazzBasic escape) to wrap the SQL for the OS shell: `SHELL("sqlite3 db.sqlite \"SELECT * FROM users\" 2>&1")`.
|
| 356 |
- In paths use `/` or `\\` — never a single `\`.
|
| 357 |
|
| 358 |
### Keyboard Input
|
| 359 |
| Function | Returns | Notes |
|
| 360 |
|----------|---------|-------|
|
| 361 |
| `INKEY` | Key value or 0 | Non-blocking |
|
| 362 |
-
| `KEYDOWN(key#)` | TRUE/FALSE | Held-key detection
|
| 363 |
| `WAITKEY(key#, ...)` | Key value | Blocks until key pressed; `WAITKEY()` = any key |
|
| 364 |
|
| 365 |
-
**
|
| 366 |
-
numpad and modifiers are the same on every keyboard layout — use these for controls.
|
| 367 |
-
Main-keyboard punctuation (`+ - = , . /` etc. and their `KEY_*#` constants) depends on the
|
| 368 |
-
layout: never bind controls to `ASC("+")` or `ASC("-")`. Use letters or
|
| 369 |
-
`KEY_NUMPAD_PLUS#` / `KEY_NUMPAD_MINUS#` instead.
|
| 370 |
-
|
| 371 |
- Letters always return uppercase codes (`"a"` and `"A"` → `KEY_A#`), in both graphics and console mode.
|
| 372 |
-
- `KEYDOWN` follows the key *label* on the current layout, same as `INKEY`
|
| 373 |
-
- Numpad
|
| 374 |
-
|
| 375 |
-
- INKEY
|
| 376 |
-
|
| 377 |
-
- Console mode: INKEY/WAITKEY return the typed character (except letters and special keys);
|
| 378 |
-
numpad returns the typed digit, not `KEY_NUMPAD*#`. KEYDOWN is graphics-only.
|
| 379 |
-
|
| 380 |
### Mouse (graphics mode only)
|
| 381 |
`MOUSEX`, `MOUSEY` — cursor position
|
| 382 |
-
`MOUSELEFT`, MOUSERIGHT, MOUSEMIDDLE —
|
| 383 |
-
`MOUSEHIDE` — hide
|
| 384 |
-
`MOUSESHOW` — restore the mouse cursor (graphics screen only)
|
| 385 |
-
|
| 386 |
-
### Gamepad (console AND graphics mode) — added in v1.5
|
| 387 |
-
|
| 388 |
-
> **DISCLAIMER:** BazzBasic version 1.5 has been tested with only one PS4-compatible Bluetooth controller. Therefore, for the time being, I cannot guarantee that GamePad support will work with all different types of controllers.
|
| 389 |
-
|
| 390 |
-
When a user reports a pad not being detected, wrong button mapping or odd axis values, keep this in mind: it may be an untested-controller issue rather than a bug in their code.
|
| 391 |
|
|
|
|
| 392 |
| Function | Returns | Notes |
|
| 393 |
|----------|---------|-------|
|
| 394 |
| `GAMEPADS()` | Number of connected pads | Parentheses optional |
|
|
@@ -397,57 +318,48 @@ When a user reports a pad not being detected, wrong button mapping or odd axis v
|
|
| 397 |
| `PADNAME(pad)` | String | e.g. `"PS4 Controller"`, `""` if not connected |
|
| 398 |
| `PADRUMBLE pad, strength, ms` | — (statement) | strength 0.0…1.0, non-blocking, parentheses optional |
|
| 399 |
|
| 400 |
-
- Pad index is **0-based**, max 8 pads.
|
| 401 |
-
- **No `SCREEN` needed** —
|
| 402 |
-
- **Disconnected pad = no input, never an error:** `PADBUTTON` → FALSE, `PADAXIS` → 0, `PADNAME` → `""`.
|
| 403 |
-
-
|
| 404 |
-
-
|
| 405 |
-
-
|
| 406 |
-
- **
|
| 407 |
-
-
|
| 408 |
-
- `PADBUTTON` is TRUE every frame while held. For one action per press, keep the previous state: `IF now$ AND NOT was$ THEN ...` then `was$ = now$`.
|
| 409 |
- Stick as digital direction: `IF PADAXIS(0, PAD_LX#) < -0.5 THEN ...`
|
| 410 |
-
-
|
| 411 |
-
- Many third-party pads identify as PS4/Xbox controllers — normal, mapping still correct.
|
| 412 |
-
|
| 413 |
-
### Console Read
|
| 414 |
-
Returns numeric or character depending on type parameter
|
| 415 |
-
`GETCONSOLE(row, col, type)` — type: 0=char (ASCII), 1=fg color, 2=bg color
|
| 416 |
|
| 417 |
---
|
| 418 |
|
| 419 |
## User-Defined Functions
|
| 420 |
|
| 421 |
```basic
|
| 422 |
-
' Define BEFORE calling. Name must end with $.
|
| 423 |
DEF FN Clamp$(val$, lo$, hi$)
|
| 424 |
IF val$ < lo$ THEN RETURN lo$
|
| 425 |
IF val$ > hi$ THEN RETURN hi$
|
| 426 |
RETURN val$
|
| 427 |
END DEF
|
| 428 |
|
| 429 |
-
PRINT FN Clamp$(5, 1, 10) ' ✓
|
| 430 |
-
LET v$ = FN Clamp$(15, 0, 10)
|
| 431 |
FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
| 432 |
```
|
| 433 |
|
| 434 |
-
-
|
| 435 |
-
-
|
| 436 |
-
|
| 437 |
DEF FN Count$(x$)
|
| 438 |
-
DIM t$
|
| 439 |
t$(x$) = 1
|
| 440 |
RETURN LEN(t$())
|
| 441 |
END DEF
|
| 442 |
PRINT FN Count$(1) ' 1
|
| 443 |
PRINT FN Count$(2) ' 1 (not 2)
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
- Parameters passed **by value**
|
| 447 |
- Labels inside functions are local — GOTO/GOSUB cannot jump outside
|
| 448 |
-
-
|
| 449 |
-
- Arrays as parameters not allowed. Use ASJSON to make array as JSON-string to pass it.
|
| 450 |
-
- Use `INCLUDE` to load functions from separate files if many
|
| 451 |
|
| 452 |
---
|
| 453 |
|
|
@@ -457,9 +369,8 @@ FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
|
| 457 |
|----------|-------------|
|
| 458 |
| `ASC(s$)` | ASCII code of first char |
|
| 459 |
| `CHR(n)` | Character from ASCII code |
|
| 460 |
-
| `INSTR(s$, search$)` | Position (1-based), 0=not found; case-sensitive
|
| 461 |
| `INSTR(s$, search$, mode)` | mode: 0=case-insensitive, 1=case-sensitive |
|
| 462 |
-
| `INSTR(start, s$, search$)` | Search from position (case-sensitive) |
|
| 463 |
| `INVERT(s$)` | Reverse string |
|
| 464 |
| `LCASE(s$)` / `UCASE(s$)` | Lower / upper case |
|
| 465 |
| `LEFT(s$, n)` / `RIGHT(s$, n)` | First/last n chars |
|
|
@@ -469,24 +380,18 @@ FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
|
| 469 |
| `MID(s$, start, len)` | Substring with length |
|
| 470 |
| `REPEAT(s$, n)` | Repeat string n times |
|
| 471 |
| `REPLACE(s$, a$, b$)` | Replace a$ with b$ in s$ |
|
| 472 |
-
| `SPLIT(arr$, s$, sep$)` | Split into array (keys `0`..`count-1`), returns count.
|
| 473 |
-
| `SRAND(n)` | Random alphanumeric string of length n |
|
| 474 |
| `STR(n)` | Number to string |
|
| 475 |
| `VAL(s$)` | String to number |
|
| 476 |
| `SHA256(s$)` | SHA256 hash (64-char hex) |
|
| 477 |
| `BASE64ENCODE(s$)` / `BASE64DECODE(s$)` | Base64 encode/decode |
|
| 478 |
|
| 479 |
-
> `SRAND(n)` with `n < 0` throws an unhandled arithmetic error (`n = 0` is safe, returns `""`). Never pass an unvalidated or negative length.
|
| 480 |
-
> ```basic
|
| 481 |
-
> PRINT SRAND(-1)
|
| 482 |
-
> ' Error: Arithmetic operation resulted in an overflow.
|
| 483 |
-
> ```
|
| 484 |
-
|
| 485 |
---
|
| 486 |
|
| 487 |
## FSTRING — String Interpolation
|
| 488 |
|
| 489 |
-
`FSTRING(template$)` substitutes `{{-name-}}` placeholders
|
| 490 |
|
| 491 |
```basic
|
| 492 |
LET name$ = "Krisu"
|
|
@@ -495,39 +400,28 @@ PRINT FSTRING("Hello {{-name$-}}, level {{-LEVEL#-}}")
|
|
| 495 |
' Output: Hello Krisu, level 5
|
| 496 |
```
|
| 497 |
|
| 498 |
-
The triple-character markers `{{-` and `-}}` are deliberately unusual
|
| 499 |
-
|
| 500 |
-
### Placeholder forms
|
| 501 |
|
| 502 |
| Form | Resolves to |
|
| 503 |
|------|-------------|
|
| 504 |
-
| `{{-var$-}}` |
|
| 505 |
-
| `{{-CONST#-}}` |
|
| 506 |
-
| `{{-arr$(0)-}}` |
|
| 507 |
-
| `{{-arr$(i$)-}}` |
|
| 508 |
-
| `{{-arr$(KEY#)-}}` |
|
| 509 |
-
| `{{-arr$(name)-}}` |
|
| 510 |
-
| `{{-arr$(0, i$)-}}` | Multidimensional
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
For each comma-separated index, FSTRING looks at the last character:
|
| 515 |
-
|
| 516 |
1. Ends with `$` or `#` → variable / constant lookup. Halts if undefined.
|
| 517 |
-
2. Parses as a number
|
| 518 |
-
3. Otherwise → literal string key.
|
| 519 |
|
| 520 |
-
|
| 521 |
|
| 522 |
-
|
| 523 |
-
- Built-in constants work too (`{{-PI#-}}`, `{{-EULER#-}}`, `{{-arr$(KEY_A#)-}}`) — checked before user variables, same order as normal expressions. (In v1.4c they failed with "undefined variable".)
|
| 524 |
-
- Numbers auto-stringify — no `STR()` needed for numeric variables, constants, or array elements.
|
| 525 |
-
- FSTRING returns a value; you must use it (`LET`, `PRINT`, pass to function). Calling it as a bare statement is an error.
|
| 526 |
-
- Errors halt the program with a line-numbered message: undefined variable, missing closing `-}}`, empty placeholder `{{--}}`, malformed array access, uninitialized array element.
|
| 527 |
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
No arithmetic, function calls, nested lookups, or quoted string literals inside placeholders. Pre-compute into a variable and reference that:
|
| 531 |
|
| 532 |
```basic
|
| 533 |
' ❌ WRONG
|
|
@@ -542,19 +436,7 @@ LET k$ = arr2$(0)
|
|
| 542 |
PRINT FSTRING("Total: {{-total$-}}, Name: {{-upper$-}}, Item: {{-arr$(k$)-}}")
|
| 543 |
```
|
| 544 |
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
```basic
|
| 548 |
-
' ❌ WRONG ' ✓ CORRECT
|
| 549 |
-
FSTRING("Hi {{name$}}") FSTRING("Hi {{-name$-}}")
|
| 550 |
-
FSTRING("Hi {-name$-}") FSTRING("Hi {{-name$-}}")
|
| 551 |
-
FSTRING("Hi {{-name-}}") ' array key FSTRING("Hi {{-name$-}}")
|
| 552 |
-
FSTRING("Hi {{-name$-}}") ' as stmt LET s$ = FSTRING("Hi {{-name$-}}")
|
| 553 |
-
```
|
| 554 |
-
|
| 555 |
-
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.
|
| 556 |
-
|
| 557 |
-
### Full working example
|
| 558 |
|
| 559 |
```basic
|
| 560 |
DIM player$
|
|
@@ -563,25 +445,17 @@ DIM player$
|
|
| 563 |
player$("level") = 99
|
| 564 |
|
| 565 |
DIM grid$
|
| 566 |
-
grid$(0, 0) = "X"
|
| 567 |
-
grid$(0, 1) = "O"
|
| 568 |
grid$(1, 0) = "."
|
| 569 |
grid$(1, 1) = "X"
|
| 570 |
|
| 571 |
LET row$ = 1
|
| 572 |
-
LET PI# = 3.14
|
| 573 |
|
| 574 |
PRINT FSTRING("{{-player$(name)-}} the {{-player$(class)-}}, lvl {{-player$(level)-}}")
|
| 575 |
PRINT FSTRING("Row {{-row$-}}: [{{-grid$(row$, 0)-}}{{-grid$(row$, 1)-}}]")
|
| 576 |
-
PRINT FSTRING("Pi is roughly {{-PI#-}}")
|
| 577 |
END
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
```
|
| 582 |
-
Krisu the Bass, lvl 99
|
| 583 |
-
Row 1: [.X]
|
| 584 |
-
Pi is roughly 3.14
|
| 585 |
```
|
| 586 |
|
| 587 |
---
|
|
@@ -592,9 +466,9 @@ Pi is roughly 3.14
|
|
| 592 |
|----------|-------------|
|
| 593 |
| `ABS(n)` | Absolute value |
|
| 594 |
| `ATAN(n)` | Arc tangent |
|
| 595 |
-
| `ATAN2(
|
| 596 |
| `BETWEEN(n, min, max)` | TRUE if min ≤ n ≤ max |
|
| 597 |
-
| `INBETWEEN(n, min, max)` | TRUE if min < n < max (
|
| 598 |
| `CEIL(n)` / `FLOOR(n)` | Round up / down |
|
| 599 |
| `CINT(n)` | Round to nearest integer |
|
| 600 |
| `CLAMP(n, min, max)` | Constrain n to [min, max] |
|
|
@@ -607,47 +481,39 @@ Pi is roughly 3.14
|
|
| 607 |
| `LERP(start, end, t)` | Linear interpolation (t: 0.0–1.0) |
|
| 608 |
| `LOG(n)` | Natural logarithm |
|
| 609 |
| `MAX(a, b)` / `MIN(a, b)` | Larger / smaller of two |
|
| 610 |
-
| `MOD(a, b)` | Remainder |
|
| 611 |
-
| `a % b` | Same as `MOD(a, b)` — binary modulo operator form |
|
| 612 |
| `POW(base, exp)` | Power |
|
| 613 |
-
| `RND(n)` | Random integer 0 to n-1
|
| 614 |
-
| `RND(0)` |
|
| 615 |
-
| `ROUND(n)` |
|
| 616 |
| `SGN(n)` | Sign: -1, 0, or 1 |
|
| 617 |
| `SQR(n)` | Square root |
|
| 618 |
|
| 619 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 620 |
|
| 621 |
---
|
| 622 |
|
| 623 |
-
##
|
| 624 |
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
- **Scalars only.** Variables (`$`) and constants (`#`). Arrays and array elements are stored separately — `ISSET(arr$)` and `ISSET(arr$(0))` always return `0`, never an error.
|
| 632 |
-
- **Bare name only.** No expressions, no string literals, no numbers. These all error with "invalid parameter":
|
| 633 |
-
```basic
|
| 634 |
-
ISSET(a$ + b$) ' WRONG: expression
|
| 635 |
-
ISSET("a$") ' WRONG: string literal
|
| 636 |
-
ISSET(42) ' WRONG: number
|
| 637 |
-
ISSET() ' WRONG: empty
|
| 638 |
-
```
|
| 639 |
-
- **Suffix is part of the name.** `a$` and `A#` are different names:
|
| 640 |
-
```basic
|
| 641 |
-
LET a$ = "foo"
|
| 642 |
-
PRINT ISSET(a$) ' 1
|
| 643 |
-
PRINT ISSET(A#) ' 0
|
| 644 |
-
```
|
| 645 |
-
- **`LET name$` (no value) still counts as set.** `LET` always registers the variable; the value just defaults to empty string for `$` and zero for numeric. `ISSET` reports declaration, not "has a meaningful value".
|
| 646 |
-
|
| 647 |
-
Typical use is guarding optional setup:
|
| 648 |
|
| 649 |
```basic
|
| 650 |
-
IF
|
| 651 |
LET playerName$ = "Anonymous"
|
| 652 |
END IF
|
| 653 |
```
|
|
@@ -664,65 +530,45 @@ FULLSCREEN TRUE ' Borderless fullscreen (graphics only)
|
|
| 664 |
FULLSCREEN FALSE ' Windowed
|
| 665 |
```
|
| 666 |
|
| 667 |
-
|
| 668 |
-
|------|-----------|
|
| 669 |
-
| 1 | 320×200 |
|
| 670 |
-
| 2 | 640×350 |
|
| 671 |
-
| 7 | 320×200 |
|
| 672 |
-
| 9 | 640×350 |
|
| 673 |
-
| 12 | 640×480 ← recommended |
|
| 674 |
-
| 13 | 320×200 |
|
| 675 |
|
| 676 |
### Drawing Primitives
|
| 677 |
```basic
|
| 678 |
-
PSET (x, y), color
|
| 679 |
-
LINE (x1,y1)-(x2,y2), color
|
| 680 |
-
LINE (x1,y1)-(x2,y2), color, B
|
| 681 |
-
LINE (x1,y1)-(x2,y2), color, BF
|
| 682 |
-
CIRCLE (cx,cy), radius, color
|
| 683 |
-
CIRCLE (cx,cy), radius, color, 1
|
| 684 |
-
PAINT (x, y), fillColor, borderColor
|
| 685 |
-
LET c$ = POINT(x, y)
|
| 686 |
-
LET
|
| 687 |
```
|
| 688 |
|
| 689 |
-
**
|
| 690 |
-
|
| 691 |
-
**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.
|
| 692 |
|
| 693 |
**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
|
| 694 |
|
| 695 |
-
> 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)`.
|
| 696 |
-
|
| 697 |
### Screen Control
|
| 698 |
```basic
|
| 699 |
-
SCREENLOCK ON '
|
| 700 |
-
SCREENLOCK OFF ' Present buffer
|
| 701 |
-
VSYNC(TRUE) ' Enable VSync (default
|
| 702 |
VSYNC(FALSE) ' Disable VSync (benchmarking)
|
| 703 |
-
CLS ' Clear screen
|
| 704 |
-
' Use CLS only with console, in graphics screen its slow
|
| 705 |
-
' With graphics screen, prefer LINE BF
|
| 706 |
```
|
| 707 |
|
| 708 |
### Shapes & Images
|
| 709 |
```basic
|
| 710 |
-
'
|
| 711 |
-
' LOADSHAPE and LOADIMAGE return a stable integer handle — never reassigned.
|
| 712 |
-
' SDL2 owns the resource; your code only ever holds this one reference. Use constants.
|
| 713 |
-
LET RECT# = LOADSHAPE("RECTANGLE", w, h, color) ' or "CIRCLE", "TRIANGLE"
|
| 714 |
LET IMG_PLAYER# = LOADIMAGE("player.png") ' PNG (alpha) or BMP
|
| 715 |
-
LET IMG_REMOTE# = LOADIMAGE("https://example.com/a.png")
|
| 716 |
|
| 717 |
' Sprite sheet — sprites indexed 0-based
|
| 718 |
DIM sprites$
|
| 719 |
-
LOADSHEET sprites$, 128, 128, "sheet.png"
|
| 720 |
-
MOVESHAPE sprites$(0), x, y
|
| 721 |
|
| 722 |
-
'
|
| 723 |
-
' NOTE: anchor point differs by type — LOADSHAPE primitives (RECTANGLE/CIRCLE/TRIANGLE)
|
| 724 |
-
' are center-anchored; LOADIMAGE images are top-left-anchored.
|
| 725 |
-
MOVESHAPE RECT#, x, y ' Position by center point (LOADSHAPE shape)
|
| 726 |
ROTATESHAPE RECT#, angle ' Degrees (absolute)
|
| 727 |
SCALESHAPE RECT#, scale ' 1.0 = original size
|
| 728 |
DRAWSHAPE RECT# ' Render to buffer
|
|
@@ -730,39 +576,28 @@ SHOWSHAPE RECT# / HIDESHAPE RECT# ' Toggle visibility
|
|
| 730 |
REMOVESHAPE RECT# ' Free memory (always clean up)
|
| 731 |
```
|
| 732 |
|
|
|
|
| 733 |
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
### Text Rendering (SDL2_ttf.dll required)
|
| 737 |
-
#### DRAWSTRING & LOADFONT
|
| 738 |
-
|
| 739 |
|
| 740 |
```basic
|
| 741 |
-
' Default font: Arial, 16px
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
' Load alternative font — becomes the new default
|
| 745 |
-
LOADFONT "comic.ttf", 24
|
| 746 |
-
DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
|
| 747 |
-
|
| 748 |
-
' Reset to Arial, 16px
|
| 749 |
-
LOADFONT
|
| 750 |
```
|
| 751 |
|
| 752 |
-
`DRAWSTRING x, y` positions the top-left of the text.
|
| 753 |
|
| 754 |
---
|
| 755 |
|
| 756 |
## Sound
|
| 757 |
|
| 758 |
```basic
|
| 759 |
-
' LOADSOUND returns a stable integer handle — SDL2 manages the resource.
|
| 760 |
-
' The handle never changes; store it in a constant to protect it from accidental reassignment.
|
| 761 |
LET SND_JUMP# = LOADSOUND("jump.wav") ' Load (WAV recommended)
|
| 762 |
SOUNDONCE(SND_JUMP#) ' Play once, non-blocking
|
| 763 |
-
SOUNDONCEWAIT(SND_JUMP#)
|
| 764 |
-
SOUNDREPEAT(SND_JUMP#)
|
| 765 |
-
SOUNDSTOP(SND_JUMP#)
|
| 766 |
SOUNDSTOPALL ' Stop all sounds
|
| 767 |
```
|
| 768 |
|
|
@@ -773,32 +608,27 @@ Load all sounds at startup. Call `SOUNDSTOPALL` before `END`.
|
|
| 773 |
## File I/O
|
| 774 |
|
| 775 |
```basic
|
| 776 |
-
LET data$ =
|
| 777 |
-
DIM cfg$ : LET cfg$ =
|
| 778 |
-
FILEWRITE "save.txt", data$
|
| 779 |
-
FILEAPPEND "log.txt", entry$
|
| 780 |
-
LET ok$ = FILEEXISTS("file.txt")
|
| 781 |
-
FILEDELETE "temp.dat"
|
| 782 |
DIM files$
|
| 783 |
-
LET n$ = FILELIST(files$, "levels", "*.txt") '
|
| 784 |
```
|
| 785 |
|
| 786 |
-
**
|
| 787 |
-
|
| 788 |
-
**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.
|
| 789 |
|
| 790 |
```basic
|
| 791 |
DIM env$
|
| 792 |
-
LET env$ =
|
| 793 |
LET API_KEY# = env$("OPENAI_API_KEY")
|
| 794 |
```
|
| 795 |
|
| 796 |
-
**
|
| 797 |
-
|
| 798 |
-
```
|
| 799 |
-
LET path$ = PRG_ROOT# + "data.txt"
|
| 800 |
-
```
|
| 801 |
-
**FileWrite with array** saves in key=value format (round-trips with FileRead).
|
| 802 |
|
| 803 |
---
|
| 804 |
|
|
@@ -808,41 +638,35 @@ LET path$ = PRG_ROOT# + "data.txt"
|
|
| 808 |
LET res$ = HTTPGET("https://api.example.com/data")
|
| 809 |
LET res$ = HTTPPOST("https://api.example.com/submit", "{""key"":""val""}")
|
| 810 |
|
| 811 |
-
'
|
| 812 |
DIM headers$
|
| 813 |
headers$("Authorization") = "Bearer mytoken"
|
| 814 |
headers$("Content-Type") = "application/json"
|
| 815 |
LET res$ = HTTPGET("https://api.example.com/data", headers$)
|
| 816 |
LET res$ = HTTPPOST("https://api.example.com/data", body$, headers$)
|
| 817 |
|
| 818 |
-
'
|
| 819 |
-
LET res$ = HTTPGET("https://api.example.com/data", headers$, 60)
|
| 820 |
LET res$ = HTTPPOST("http://localhost:11434/v1/chat/completions", body$, headers$, 120)
|
| 821 |
```
|
| 822 |
|
| 823 |
### Local HTTP server (LISTEN)
|
| 824 |
|
| 825 |
-
|
| 826 |
|
| 827 |
```basic
|
| 828 |
-
STARTLISTEN 8080 '
|
| 829 |
-
STARTLISTEN 8080, 5000 '
|
| 830 |
-
LET body$ = GETREQUEST() ' POST/PUT/PATCH body
|
| 831 |
-
SENDRESPONSE "{""status"":""ok""}" '
|
| 832 |
STOPLISTEN
|
| 833 |
```
|
| 834 |
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
- **
|
| 838 |
-
- **
|
| 839 |
-
- **
|
| 840 |
-
- **
|
| 841 |
-
- **CORS is automatic.** Every response carries `Access-Control-Allow-Origin: *`. No need to set it manually.
|
| 842 |
-
- **One listener at a time.** Calling `STARTLISTEN` while one is already active is an error. Call `STOPLISTEN` first.
|
| 843 |
-
- **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.
|
| 844 |
-
|
| 845 |
-
Typical receive-and-process pattern:
|
| 846 |
|
| 847 |
```basic
|
| 848 |
STARTLISTEN 8080
|
|
@@ -850,8 +674,7 @@ PRINT "Waiting for browser..."
|
|
| 850 |
|
| 851 |
LET json$ = GETREQUEST()
|
| 852 |
DIM data$
|
| 853 |
-
LET
|
| 854 |
-
|
| 855 |
PRINT "Got name: " + data$("name")
|
| 856 |
|
| 857 |
SENDRESPONSE "{""status"":""ok""}"
|
|
@@ -863,66 +686,70 @@ END
|
|
| 863 |
|
| 864 |
## Arrays & JSON
|
| 865 |
|
| 866 |
-
Nested JSON maps to comma-separated keys: `data$("player,name")`, `data$("skills,0")`
|
| 867 |
|
| 868 |
```basic
|
| 869 |
-
' Array → JSON string
|
| 870 |
-
LET json$ = ASJSON(arr$)
|
| 871 |
-
|
| 872 |
-
' JSON string → array (returns element count)
|
| 873 |
DIM data$
|
| 874 |
-
LET count$ = ASARRAY(data$, json$)
|
| 875 |
-
|
| 876 |
-
'
|
| 877 |
-
LOADJSON arr$, "file.json"
|
| 878 |
-
SAVEJSON arr$, "file.json"
|
| 879 |
```
|
| 880 |
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
## Fast Trigonometry
|
| 884 |
|
| 885 |
-
|
| 886 |
|
| 887 |
```basic
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
LET
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 894 |
|
| 895 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 896 |
|
| 897 |
---
|
| 898 |
|
| 899 |
## Date & Time
|
| 900 |
|
| 901 |
```basic
|
| 902 |
-
LET t$
|
| 903 |
-
LET t2$ = TIME("dd.MM.yyyy") ' .NET DateTime format
|
| 904 |
LET t3$ = TIME("dddd") ' -> "Friday"
|
| 905 |
-
|
| 906 |
LET start$ = TICKS ' Milliseconds since program start
|
| 907 |
-
' ... later in a loop ...
|
| 908 |
-
LET elapsed$ = TICKS - start$ ' Delta time — use for frame-independent movement
|
| 909 |
```
|
| 910 |
|
| 911 |
-
|
|
|
|
|
|
|
|
|
|
| 912 |
|
| 913 |
```basic
|
| 914 |
-
|
| 915 |
-
LET
|
| 916 |
-
|
| 917 |
-
LET delta$
|
| 918 |
-
|
| 919 |
-
x$ = x$ + speed$ * delta$ / 16 ' normalize to ~60 FPS baseline
|
| 920 |
-
GOSUB [sub:draw]
|
| 921 |
-
WEND
|
| 922 |
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 926 |
```
|
| 927 |
|
| 928 |
---
|
|
@@ -931,12 +758,12 @@ x$ = x$ + speed$
|
|
| 931 |
|
| 932 |
```basic
|
| 933 |
' bazzbasic.exe myprog.bas arg1 arg2
|
| 934 |
-
PRINT ARGCOUNT '
|
| 935 |
-
PRINT ARGS(0) '
|
| 936 |
-
PRINT ARGS(1) '
|
| 937 |
```
|
| 938 |
|
| 939 |
-
|
| 940 |
|
| 941 |
---
|
| 942 |
|
|
@@ -952,60 +779,30 @@ INCLUDE "MathLib.bb" ' Load compiled library
|
|
| 952 |
PRINT FN MATHLIB_add$(5, 3)
|
| 953 |
```
|
| 954 |
|
| 955 |
-
Library functions can read main-program constants (`#`).
|
| 956 |
-
|
| 957 |
-
- **No extension fallback
|
| 958 |
-
- **Path resolution
|
| 959 |
-
- **Circular includes
|
| 960 |
-
|
| 961 |
-
---
|
| 962 |
-
|
| 963 |
-
## Passing Arrays to Functions
|
| 964 |
-
|
| 965 |
-
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+.
|
| 966 |
-
|
| 967 |
-
```basic
|
| 968 |
-
DEF FN ProcessPlayer$(data$)
|
| 969 |
-
DIM arr$
|
| 970 |
-
LET count$ = ASARRAY(arr$, data$)
|
| 971 |
-
RETURN arr$("name") + " score:" + arr$("score")
|
| 972 |
-
END DEF
|
| 973 |
-
|
| 974 |
-
[inits]
|
| 975 |
-
DIM player$
|
| 976 |
-
player$("name") = "Alice"
|
| 977 |
-
player$("score") = 9999
|
| 978 |
-
player$("address,city") = "New York"
|
| 979 |
-
|
| 980 |
-
[main]
|
| 981 |
-
LET json$ = ASJSON(player$)
|
| 982 |
-
PRINT FN ProcessPlayer$(json$)
|
| 983 |
-
END
|
| 984 |
-
```
|
| 985 |
-
|
| 986 |
-
**Notes:**
|
| 987 |
-
- The function receives a full independent copy — changes inside do not affect the original array
|
| 988 |
-
- Nested keys work normally: `arr$("address,city")` etc.
|
| 989 |
-
- Overhead is similar to copying an array manually; acceptable for most use cases
|
| 990 |
|
| 991 |
---
|
| 992 |
|
| 993 |
## Program Structure
|
| 994 |
|
| 995 |
```basic
|
| 996 |
-
' ---- 1. FUNCTIONS (or INCLUDE
|
| 997 |
DEF FN Clamp$(v$, lo$, hi$)
|
| 998 |
IF v$ < lo$ THEN RETURN lo$
|
| 999 |
IF v$ > hi$ THEN RETURN hi$
|
| 1000 |
RETURN v$
|
| 1001 |
END DEF
|
| 1002 |
|
| 1003 |
-
' ---- 2. INIT
|
| 1004 |
-
' Performance: variables declared outside loops avoid repeated existence checks.
|
| 1005 |
[inits]
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
|
|
|
| 1009 |
|
| 1010 |
SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
|
| 1011 |
|
|
@@ -1018,13 +815,12 @@ END DEF
|
|
| 1018 |
WHILE running$
|
| 1019 |
IF INKEY = KEY_ESC# THEN running$ = FALSE
|
| 1020 |
GOSUB [sub:update]
|
| 1021 |
-
GOSUB [sub:draw]
|
| 1022 |
-
SLEEP 16
|
| 1023 |
WEND
|
| 1024 |
SOUNDSTOPALL
|
| 1025 |
-
END
|
| 1026 |
|
| 1027 |
-
' ---- 4. SUBROUTINES (or INCLUDE
|
| 1028 |
[sub:update]
|
| 1029 |
IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED#
|
| 1030 |
IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED#
|
|
@@ -1033,139 +829,43 @@ RETURN
|
|
| 1033 |
[sub:draw]
|
| 1034 |
SCREENLOCK ON
|
| 1035 |
LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
|
| 1036 |
-
CIRCLE (x$, y$), 10,
|
| 1037 |
SCREENLOCK OFF
|
| 1038 |
RETURN
|
| 1039 |
```
|
| 1040 |
|
| 1041 |
-
**
|
| 1042 |
-
- Variables: `camelCase$` | Constants: `UPPER_SNAKE_CASE#` | Functions: `PascalCase$`
|
| 1043 |
-
- Labels: `[gameLoop]` for jump targets, `[sub:name]` for subroutines
|
| 1044 |
-
- Image/sound/shape IDs are stable integer handles — **always** store as constants: `LET MY_IMG# = LOADIMAGE("x.png")` — never use `$` variables for these
|
| 1045 |
-
- Group many IDs → use arrays: `DIM sprites$` / `sprites$("player") = LOADIMAGE(...)` — but prefer named constants when count is small
|
| 1046 |
|
| 1047 |
---
|
| 1048 |
|
| 1049 |
-
##
|
| 1050 |
|
| 1051 |
-
|
| 1052 |
-
- Always wrap draw code in `SCREENLOCK ON` / `SCREENLOCK OFF`
|
| 1053 |
-
- Store `RGB()` results in constants/variables — don't call RGB in hot loops
|
| 1054 |
-
- Declare all variables in `[inits]`, not inside loops or subroutines
|
| 1055 |
-
- Use `FastTrig` for any loop calling trig hundreds of times per frame
|
| 1056 |
-
- `SLEEP 16` in game loop → ~60 FPS
|
| 1057 |
|
| 1058 |
-
---
|
| 1059 |
-
|
| 1060 |
-
## Known Limitations
|
| 1061 |
-
|
| 1062 |
-
Things to be aware of — most are deliberate design decisions, a few are practical constraints.
|
| 1063 |
-
|
| 1064 |
-
- **No line numbers.** Never supported, never will be.
|
| 1065 |
-
- **Platform: Windows x64 only.** Linux and macOS are not supported. Browser/Android are not feasible — the runtime depends on SDL2 via P/Invoke.
|
| 1066 |
-
- **Arrays cannot be passed to functions.** Use the `ASJSON` / `ASARRAY` round-trip pattern. The function receives an independent copy.
|
| 1067 |
-
- **`DEF FN` scope is fully isolated.** Functions can read global `#` constants but cannot see any `$` variables or arrays from the outer scope. Pass values as parameters, arrays as `ASJSON()` strings.
|
| 1068 |
-
- **No block scope.** `IF`, `FOR`, and `WHILE` do not create new variable scopes — all main-code variables share one namespace.
|
| 1069 |
-
- **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, and the process exits with code 1.
|
| 1070 |
-
- **Division by zero returns `0` silently.** No exception, no warning. Guard with `IF b$ = 0 THEN ...` when correctness matters.
|
| 1071 |
-
- **No integer-division operator.** Use `INT(a / b)`, `FLOOR(a / b)`, or `CINT(a / b)` depending on the rounding behavior you need.
|
| 1072 |
-
- **Compiled `.bb` libraries are version-locked** to the BazzBasic build that produced them. Recompile after upgrading the interpreter.
|
| 1073 |
-
- **`DEF FN` definitions must precede their first call** in source order. Forward references don't resolve.
|
| 1074 |
-
|
| 1075 |
-
---
|
| 1076 |
-
|
| 1077 |
-
## Interpreter, IDE and Command Line
|
| 1078 |
-
|
| 1079 |
-
### Two programs: BazzBasic.exe and BazzBasic-IDE.exe
|
| 1080 |
-
|
| 1081 |
-
BazzBasic ships as two programs in the same folder:
|
| 1082 |
-
|
| 1083 |
-
| File | What it is |
|
| 1084 |
-
|------|------------|
|
| 1085 |
-
| `BazzBasic.exe` | The interpreter — a console program that runs and compiles `.bas` files (~15 MB) |
|
| 1086 |
-
| `BazzBasic-IDE.exe` | The code editor — a Windows program (~111 MB, WinForms + Scintilla) |
|
| 1087 |
-
|
| 1088 |
-
- Command line, `.bat` files, other editors (Notepad++, Geany, VS Code), PATH and `.bas` file associations all keep using `BazzBasic.exe` as before.
|
| 1089 |
-
- Running `BazzBasic.exe` with no arguments (or double-clicking it) starts `BazzBasic-IDE.exe` from the same folder. If the IDE isn't there, it prints the command-line usage instead.
|
| 1090 |
-
- To use only the interpreter with another editor, `BazzBasic-IDE.exe` and the `runtimes` folder can be left out; the interpreter only needs the SDL2 DLLs next to it.
|
| 1091 |
-
- **Compiled programs** (`-exe` / Compile as Exe) are a copy of the interpreter with the code inside, so they are about 15 MB.
|
| 1092 |
-
- **Before v1.6 this was completely different:** `BazzBasic.exe` was the IDE and the interpreter in one ~111 MB file, and every compiled program was that size too. There was no `BazzBasic-IDE.exe`. If a user describes a single exe, they are on an older version.
|
| 1093 |
-
|
| 1094 |
-
### Command-line options
|
| 1095 |
-
|
| 1096 |
-
| Command | Action |
|
| 1097 |
-
|---------|--------|
|
| 1098 |
-
| `bazzbasic.exe file.bas [args...]` | Run a program (`ARGS`/`ARGCOUNT` see the extra arguments) |
|
| 1099 |
-
| `bazzbasic.exe -exe file.bas` | Compile to a standalone `.exe` |
|
| 1100 |
-
| `bazzbasic.exe -lib file.bas` | Compile to a `.bb` library |
|
| 1101 |
-
| `bazzbasic.exe -v` / `-version` | Print version |
|
| 1102 |
-
| `bazzbasic.exe -guide` / `-help` | Print the Beginner's Guide URL |
|
| 1103 |
-
| `bazzbasic.exe -checkupdate` / `-checkupdates` | Check for a newer release |
|
| 1104 |
-
| `bazzbasic.exe` (no arguments) | Start the IDE |
|
| 1105 |
-
|
| 1106 |
-
**Exit code:** a program that stops on a runtime error exits with code **1**, a normal end with **0**. This also applies to compiled executables, so `.bat` files and scripts can test `ERRORLEVEL`. (Before v1.6, errors also exited with 0.)
|
| 1107 |
-
|
| 1108 |
-
---
|
| 1109 |
-
|
| 1110 |
-
## IDE Features
|
| 1111 |
-
|
| 1112 |
-
### Menus
|
| 1113 |
| Menu | Items |
|
| 1114 |
|------|-------|
|
| 1115 |
-
| **File** | New
|
| 1116 |
-
| **Edit** | Undo
|
| 1117 |
-
| **Search** | Find
|
| 1118 |
-
| **View** | Tree View (
|
| 1119 |
-
| **Run** | Run Program (F5), Compile as Exe, Compile as Library (.bb), Path to BazzBasic.exe
|
| 1120 |
-
| **Help** | About, Homepage, Online Manual, Beginner's Guide, Rosetta Code, Check for Updates
|
| 1121 |
-
|
| 1122 |
-
All IDE settings (theme, session, Tree View, window placement, interpreter path) are saved to `%AppData%\BazzBasic\ide.json`.
|
| 1123 |
-
|
| 1124 |
-
**Version note:** the IDE before v1.6 was much more limited. It had no Save All, Close All, session restore, Print, Comment/Uncomment Selection, Tree View, Zoom, screenshot, Open Console/File Browser, Path to BazzBasic.exe or Help → Homepage, and it did not remember its window size. In v1.4c and older, Find and Replace were under **Edit** and there was no View menu. If a user can't find a menu item, ask which version they run.
|
| 1125 |
-
|
| 1126 |
-
### Editing
|
| 1127 |
-
- **Comment Selection (Ctrl+Q)** adds `' ` to the start of every selected line (or the cursor line). BazzBasic has no block comments, so this is the way to disable a block of code. **Uncomment Selection (Ctrl+Shift+Q)** removes a leading `'` (and one following space), also after indentation; `REM` lines are not touched. Each is one Undo step.
|
| 1128 |
-
- **Zoom In / Zoom Out** changes the editor text size of the active tab. Both numpad and main-keyboard `+`/`-` work.
|
| 1129 |
-
|
| 1130 |
-
### Tree View
|
| 1131 |
-
**View → Tree View** shows a panel left of the editor listing the active file's **Functions** (every `DEF FN` line, with parameters) and **Labels** (every `[label]` alone on its line, e.g. `[sub:draw]`). Clicking an item jumps to that line. Updates half a second after typing stops. Code from `INCLUDE` files is not listed. Width is adjustable by dragging.
|
| 1132 |
-
|
| 1133 |
-
### Files, tabs and sessions
|
| 1134 |
-
- **Save All** saves every modified tab (Untitled tabs open Save As). **Close All** closes all tabs, asking Yes/No/Cancel for each modified one.
|
| 1135 |
-
- Closing the IDE (X, Alt+F4, File → Exit) asks to save each modified tab; Cancel keeps it open.
|
| 1136 |
-
- **Restore Session on Startup** (off by default): reopens the files that were open last time and selects the active tab. Untitled tabs aren't restored; missing files are skipped and listed once.
|
| 1137 |
-
- The IDE remembers its window size, position and maximized state between sessions.
|
| 1138 |
-
- **Print (Ctrl+P)** prints the active file with syntax highlighting on white paper. Choose *Microsoft Print to PDF* to make a PDF.
|
| 1139 |
-
|
| 1140 |
-
### Running programs
|
| 1141 |
-
- **Run Program (F5)** saves the file and runs it in a console window. A file that already has a name is saved over; an Untitled file opens the Save As dialog first. If the program stops on an error, the console stays open showing the error until a key is pressed; a normal end closes it.
|
| 1142 |
-
- **Run → Path to BazzBasic.exe...** sets which interpreter Run and Compile use. Lookup order: the path set here → the IDE's own folder → `PATH`. If a set path no longer exists, the IDE says so instead of silently using another one.
|
| 1143 |
-
|
| 1144 |
-
### Other tools
|
| 1145 |
-
- **View → Open Console** / **Open File Browser** open `cmd.exe` / File Explorer in the active file's folder (Untitled tab → the IDE's folder).
|
| 1146 |
-
- **View → Take Screenshot to Clipboard** copies an image of the IDE window only. When asking for help, prefer sharing the code as text; use the screenshot when the layout or an error dialog matters.
|
| 1147 |
-
- **Help → Homepage** opens https://ekbass.github.io/BazzBasic/.
|
| 1148 |
-
|
| 1149 |
-
### New File Template
|
| 1150 |
-
When the IDE opens with no file (or a new file), this template is auto-inserted:
|
| 1151 |
-
```basic
|
| 1152 |
-
' BazzBasic version {ver_num}
|
| 1153 |
-
' https://ekbass.github.io/BazzBasic/
|
| 1154 |
-
```
|
| 1155 |
|
| 1156 |
-
|
| 1157 |
-
|
| 1158 |
-
|
| 1159 |
|
| 1160 |
-
|
| 1161 |
-
-
|
| 1162 |
-
-
|
| 1163 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1164 |
|
| 1165 |
-
##
|
| 1166 |
-
- **IDE:** Menu → **Help** → **Check for Updates...** — IDE reports if a newer version is available
|
| 1167 |
-
- **CLI:** `bazzbasic.exe -checkupdates`
|
| 1168 |
|
| 1169 |
-
|
| 1170 |
-
-
|
| 1171 |
-
-
|
|
|
|
| 1 |
---
|
| 2 |
name: bazzbasic-code
|
| 3 |
+
description: "BazzBasic BASIC interpreter language reference. Use when writing, debugging, or explaining BazzBasic code (.bas files). Triggers on BazzBasic syntax, $ and # variable suffixes, SDL2 graphics in BASIC, SCREEN/DRAWSHAPE/LOADIMAGE commands, DEF FN functions, BazzBasic file I/O, sound commands, or any question about BazzBasic features. Always use this skill before writing any BazzBasic code. "
|
| 4 |
---
|
| 5 |
|
| 6 |
# BazzBasic Language Reference
|
| 7 |
+
**Version:** 1.6 | **Author:** Kristian Virtanen (EkBass) | **Platform:** Windows x64 only (SDL2 via P/Invoke — no Linux, macOS, browser or Android)
|
| 8 |
**Homepage:** https://ekbass.github.io/BazzBasic/
|
| 9 |
**GitHub:** https://github.com/EkBass/BazzBasic
|
| 10 |
**Manual:** https://ekbass.github.io/BazzBasic/manual/#/
|
|
|
|
| 13 |
**Rosetta Code solutions:** https://github.com/EkBass/BazzBasic/tree/main/Examples/rosetta-code
|
| 14 |
**BazzBasic-AI-Guide:** https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
|
| 15 |
**BazzBasic Beginner's Guide:** https://github.com/EkBass/BazzBasic-Beginners-Guide/releases
|
| 16 |
+
|
| 17 |
+
BazzBasic is a BASIC meant for beginners and for small, fun experiments (simple games, quizzes, bouncing balls). It is not a high-performance game engine — keep generated code simple and readable rather than clever.
|
| 18 |
|
| 19 |
---
|
| 20 |
|
|
|
|
| 22 |
|
| 23 |
| Rule | Detail |
|
| 24 |
|------|--------|
|
| 25 |
+
| Variables end with `$` | `name$`, `score$`, `x$` — the suffix does NOT mean string type |
|
| 26 |
+
| Constants end with `#` | `MAX#`, `PI#`, `TITLE#` — `#` only means immutable |
|
| 27 |
| Arrays declared with `DIM`, end with `$` | `DIM items$` |
|
| 28 |
| First use of variable requires `LET` | `LET x$ = 0` — after that `x$ = x$ + 1` |
|
| 29 |
| FOR and INPUT auto-declare, no LET needed | `FOR i$ = 1 TO 10` |
|
| 30 |
+
| Case-insensitive | Keywords, variables and labels. Only string contents are case-sensitive |
|
| 31 |
+
| Functions defined **before** they are called | Put at top or INCLUDE — forward references don't resolve |
|
| 32 |
| Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
|
| 33 |
| Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
|
| 34 |
+
| `DEF FN` scope is fully isolated | Only global `#` constants are visible. No `$` variables, no global arrays. Arrays cannot be passed as parameters — see *Passing Arrays to Functions* |
|
| 35 |
+
| `+` does both add and concatenate | If either side is a string, the other is auto-converted: `"Score: " + 5` → `"Score: 5"`, no `STR()` needed |
|
|
|
|
| 36 |
| Division always returns float | `10 / 3` → `3.333...` |
|
| 37 |
+
| Division by zero returns `0` silently | Guard with `IF b$ = 0 THEN ...` if correctness matters |
|
| 38 |
| No integer-division operator | Use `INT(a / b)`, `FLOOR(a / b)`, or `CINT(a / b)` |
|
| 39 |
| Errors halt the program | No `TRY`/`CATCH` or `ON ERROR` — line-numbered message printed |
|
| 40 |
+
| No line-continuation char | Leave an operator at line end or open a `(` — see *Line Continuation* |
|
| 41 |
+
| No line numbers | Never supported. Use `[labels]` |
|
| 42 |
+
| `:` separates statements on one line | `FOR i$ = 1 TO 3 : PRINT i$ : NEXT`. A `:` inside a label like `[sub:init]` is part of the label name, not a separator |
|
| 43 |
+
| `NOT` binds tighter than comparisons | `NOT a$ = b$` means `(NOT a$) = b$`. Parenthesize: `IF NOT (a$ = b$) THEN`, or use `<>` |
|
| 44 |
+
| Comments: `'` or `REM` | `' comment` anywhere on a line; `REM` as a statement, also after `:` (`PRINT x$ : REM note`) |
|
| 45 |
|
| 46 |
---
|
| 47 |
|
|
|
|
| 58 |
FN MyFunc$(5) ' return ignored LET v$ = FN MyFunc$(5)
|
| 59 |
LET handle$ = LOADIMAGE("x.png") LET HANDLE# = LOADIMAGE("x.png")
|
| 60 |
CLS ' in graphics mode LINE (0,0)-(W,H), 0, BF
|
| 61 |
+
PRINT "x:", x$ ' in graphics mode DRAWSTRING "x:" + x$, 10, 10, WHITE#
|
| 62 |
FSTRING("Hi {{name$}}") ' Python-style FSTRING("Hi {{-name$-}}") ' triple-char markers
|
| 63 |
ISSET(arr$(0)) ' expecting error ' returns 0 silently — ISSET only sees scalars
|
| 64 |
LET x$ = a$ + _ ' VBA continuation LET x$ = a$ + ' just leave the operator
|
| 65 |
+
LET x$ = a$ + \ ' Python continuation LET x$ = a$ + ' or open a paren
|
| 66 |
+
IF NOT a$ = b$ THEN ' QBASIC habit IF NOT (a$ = b$) THEN
|
| 67 |
```
|
| 68 |
|
| 69 |
+
---
|
| 70 |
|
| 71 |
+
## When Generating BazzBasic Code
|
| 72 |
+
|
| 73 |
+
- Prefer `FSTRING` over long `+` concatenation chains for multi-variable strings
|
| 74 |
+
- Place `DEF FN` definitions at the top of the file or via `INCLUDE`
|
| 75 |
+
- Store every `LOADIMAGE` / `LOADSOUND` / `LOADSHAPE` handle as a `#` constant. They return stable integer handles owned by SDL2 that never change. For many handles, an array is fine: `sprites$("player") = LOADIMAGE(...)`
|
| 76 |
+
- Declare all variables and constants in `[inits]`, not inside loops — this avoids repeated existence checks
|
| 77 |
+
- Precompute colors: `LET WHITE# = RGB(255, 255, 255)` in `[inits]`, never `RGB()` inside a game loop
|
| 78 |
+
- In graphics mode: clear with `LINE (0,0)-(W,H), 0, BF` (much faster than `CLS`), draw text with `DRAWSTRING` (`PRINT` flickers), and wrap each frame in `SCREENLOCK ON` / `SCREENLOCK OFF`
|
| 79 |
+
- 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
|
| 80 |
|
| 81 |
---
|
| 82 |
|
| 83 |
## Minimal Valid Program
|
| 84 |
|
| 85 |
```basic
|
| 86 |
+
[inits] ' [name] is a plain jump label, not a keyword
|
|
|
|
| 87 |
LET name$ = "World"
|
| 88 |
|
| 89 |
[main]
|
| 90 |
PRINT "Hello, " + name$
|
| 91 |
END
|
| 92 |
|
| 93 |
+
' subroutines go after END
|
| 94 |
[sub:drawScreen]
|
| 95 |
+
' draw
|
| 96 |
RETURN
|
| 97 |
```
|
| 98 |
|
| 99 |
+
Programs flow top to bottom. `[inits]` and `[main]` are organizational labels, not required syntax. `END` halts execution; place it at the end of the main flow so control doesn't fall through into subroutines.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
---
|
| 102 |
|
| 103 |
## Line Continuation
|
| 104 |
|
| 105 |
+
The lexer figures out continuation automatically using two rules. Never emit `_`, `\`, `&` or any other continuation marker.
|
| 106 |
|
| 107 |
**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:
|
| 108 |
|
|
|
|
| 121 |
|
| 122 |
Tokens that trigger this: `+ - * / % = <> < <= > >= AND OR += -= *= /= ,`
|
| 123 |
|
| 124 |
+
> `%` is a real binary modulo operator and triggers continuation. `MOD(a, b)` is a function, so it does not (a `)` at line end never continues).
|
|
|
|
| 125 |
|
| 126 |
**Rule 2 — open paren.** Anything inside an unmatched `(` keeps reading until the matching `)`:
|
| 127 |
|
|
|
|
| 132 |
)
|
| 133 |
```
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
---
|
| 136 |
|
| 137 |
## Variables & Constants
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
Variables are dynamically typed, like in JavaScript.
|
| 140 |
+
|
| 141 |
```basic
|
| 142 |
+
LET a$ ' Declare without value
|
| 143 |
+
LET b$, c$, d$ ' Multiple declarations without value
|
| 144 |
+
LET e$, f$ = "foo", g$ = 10 ' e$ stays empty, f$ and g$ get values
|
| 145 |
|
| 146 |
+
LET name$ = "Alice" ' String
|
| 147 |
+
LET score$ = 0 ' Number
|
| 148 |
|
| 149 |
+
LET PI# = 3.14159 ' Constant (immutable)
|
| 150 |
+
LET TITLE# = "My Game" ' String constant
|
| 151 |
```
|
| 152 |
|
| 153 |
+
**Compound assignment** (variables only — **not** allowed with `#` constants):
|
| 154 |
|
| 155 |
```basic
|
| 156 |
LET x$ = 1
|
| 157 |
+
x$ += 5
|
| 158 |
+
x$ -= 3
|
| 159 |
+
x$ *= 2
|
| 160 |
+
x$ /= 4
|
| 161 |
LET s$ = "Hello"
|
| 162 |
+
s$ += " World" ' concatenation
|
| 163 |
```
|
| 164 |
|
| 165 |
+
**Scope:** All main-code variables share one scope — `IF`, `FOR`, and `WHILE` do NOT create a new scope.
|
|
|
|
|
|
|
| 166 |
|
| 167 |
**Comparison:** `"123" = 123` is TRUE (cross-type), but keep types consistent for speed.
|
| 168 |
|
|
|
|
|
|
|
| 169 |
### Built-in Constants
|
| 170 |
+
- **Boolean:** `TRUE` (`1`), `FALSE` (`0`) — plain numbers. `IF x$ = 1` and `IF x$ = TRUE` are identical.
|
| 171 |
+
- **Math:** `PI#`, `HPI#` (π/2 = 90°), `QPI#` (π/4 = 45°), `TAU#` (2π = 360°), `EULER#` (e)
|
| 172 |
+
- **System:** `PRG_ROOT#` (program base directory path, ends with a separator)
|
| 173 |
+
- **Version:** `BBVER#` (current BazzBasic version as a string, e.g. `"1.6"`)
|
| 174 |
+
- **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_NUMPAD0#`…`KEY_NUMPAD9#`, `KEY_NUMPAD_PLUS#`, `_MINUS#`, `_MUL#`, `_DIV#`, `_DOT#`, `KEY_LSHIFT#`, `KEY_LCTRL#`, `KEY_RSHIFT#`, `KEY_RCTRL#`, `KEY_LALT#`, `KEY_RALT#`, `KEY_LWIN#`/`KEY_RWIN#`, `KEY_TAB#`, `KEY_BACKSPACE#`, `KEY_INSERT#`, `KEY_DELETE#`, `KEY_HOME#`, `KEY_END#`, `KEY_PGUP#`, `KEY_PGDN#` — see *Keyboard Input*
|
| 175 |
+
- **Gamepad:** see *Gamepad*
|
| 176 |
|
| 177 |
---
|
| 178 |
|
| 179 |
## Arrays
|
|
|
|
| 180 |
|
| 181 |
+
Arrays are fully dynamic and support numeric, string, or mixed indexing.
|
| 182 |
|
| 183 |
```basic
|
| 184 |
DIM scores$ ' Declare (required before use)
|
| 185 |
DIM a$, b$, c$ ' Multiple
|
| 186 |
+
scores$(0) = 95 ' Numeric indices are 0-based
|
| 187 |
+
scores$("name") = "Alice" ' String keys: associative, insertion-ordered
|
| 188 |
matrix$(0, 1) = "A2" ' Multi-dimensional
|
| 189 |
|
| 190 |
DIM sounds$
|
| 191 |
+
sounds$("guns", "shotgun_shoot") = "shoot_shotgun.wav"
|
| 192 |
+
sounds$("guns", "ak47_shoot") = "shoot_ak47.wav"
|
| 193 |
+
sounds$("food", "ham_eat") = "eat_ham.wav"
|
|
|
|
|
|
|
| 194 |
|
| 195 |
+
PRINT LEN(sounds$()) ' 3 - total elements across all groups
|
| 196 |
+
PRINT ROWCOUNT(sounds$()) ' 2 - "guns" & "food"
|
| 197 |
|
| 198 |
DIM car$
|
| 199 |
car$("manufacturer") = "Ford"
|
| 200 |
car$("engine") = "1.6 Eco"
|
|
|
|
| 201 |
|
| 202 |
+
FOR i$ = 0 TO LEN(car$()) - 1 ' No FOREACH — LEN + ARRKEY is the idiom
|
| 203 |
+
LET key$ = ARRKEY(car$(), i$)
|
| 204 |
PRINT key$; " = "; car$(key$)
|
| 205 |
NEXT i$
|
| 206 |
```
|
| 207 |
|
| 208 |
| Function/Command | Description |
|
| 209 |
|-----------------|-------------|
|
| 210 |
+
| `LEN(arr$())` | Total element count across all dimensions |
|
| 211 |
| `ROWCOUNT(arr$())` | Count of first-dimension rows — use this for FOR loops over multi-dim arrays |
|
| 212 |
+
| `ARRKEY(arr$(), i)` | Key at 0-based index `i`, in insertion order. Errors on out-of-range index |
|
| 213 |
+
| `HASKEY(arr$(key))` | 1 if exists, 0 if not — **always check before reading possibly uninitialized elements** |
|
| 214 |
| `DELKEY arr$(key)` | Remove one element |
|
| 215 |
| `DELARRAY arr$` | Remove entire array (can re-DIM after) |
|
| 216 |
+
| `JOIN dest$, src1$, src2$` | Merge two arrays; matching `src2$` keys overwrite `src1$` at the same level. Use an empty `src1$` to copy an array |
|
|
|
|
|
|
|
| 217 |
|
| 218 |
+
> `DIM arr$ = value` stores the value at `arr$(0)` — NOT as a scalar. If a scalar is what you want, use `LET`.
|
|
|
|
|
|
|
| 219 |
|
| 220 |
---
|
| 221 |
|
|
|
|
| 244 |
x$ = x$ * 2
|
| 245 |
WEND
|
| 246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
' Labels, GOTO, GOSUB
|
| 248 |
[start]
|
| 249 |
GOSUB [sub:init]
|
| 250 |
+
GOTO [start] ' Avoid jumping into the middle of IF/WHILE blocks
|
|
|
|
| 251 |
|
| 252 |
[sub:init]
|
| 253 |
LET x$ = 0
|
|
|
|
| 257 |
LET target$ = "[menu]"
|
| 258 |
GOTO target$
|
| 259 |
|
|
|
|
| 260 |
SLEEP 2000 ' Pause for milliseconds
|
| 261 |
END ' Terminate program
|
| 262 |
```
|
| 263 |
+
|
| 264 |
+
Labels may contain almost any printable character. Whitespace is trimmed; everything between `[` and `]` is the label name.
|
| 265 |
+
|
| 266 |
---
|
| 267 |
|
| 268 |
## I/O
|
| 269 |
|
| 270 |
| Command | Description |
|
| 271 |
|---------|-------------|
|
| 272 |
+
| `PRINT expr; expr` | `;` = no space, `,` = tab, can be mixed |
|
| 273 |
| `PRINT "text";` | Trailing `;` suppresses newline |
|
| 274 |
+
| `INPUT "prompt", var$` | Splits on whitespace/comma; quoted strings are single values |
|
| 275 |
| `INPUT "prompt", a$, b$` | Multiple values |
|
| 276 |
| `LINE INPUT "prompt", var$` | Read entire line with spaces |
|
| 277 |
+
| `CLS` | Clear screen (console) |
|
| 278 |
| `LOCATE row, col` | Move cursor (1-based) |
|
| 279 |
| `CURPOS("row")` / `CURPOS("col")` | Read cursor row or col (1-based, matches LOCATE) |
|
| 280 |
| `CURPOS()` | Read cursor as `"row,col"` string |
|
| 281 |
+
| `COLOR fg, bg` | Text colors, palette 0–15 only (`RGB()` does not work here) |
|
| 282 |
+
| `GETCONSOLE(row, col, type)` | Read console cell. type: 0=char (ASCII), 1=fg color, 2=bg color |
|
| 283 |
| `SHELL("cmd")` | Run shell command, returns output |
|
| 284 |
| `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
|
| 285 |
|
| 286 |
+
**Escape sequences in strings:** `\"` `\n` `\t` `\\` `""`
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
+
**SHELL + SQLite.** The `sqlite3` CLI is the recommended way to add a database — see the *SQLite Database* page in the manual. When wrapping SQL in SHELL:
|
| 289 |
+
- Always append `2>&1`, or SQL errors disappear silently.
|
| 290 |
+
- Wrap the SQL with `\"`: `SHELL("sqlite3 db.sqlite \"SELECT * FROM users\" 2>&1")`.
|
|
|
|
|
|
|
| 291 |
- In paths use `/` or `\\` — never a single `\`.
|
| 292 |
|
| 293 |
### Keyboard Input
|
| 294 |
| Function | Returns | Notes |
|
| 295 |
|----------|---------|-------|
|
| 296 |
| `INKEY` | Key value or 0 | Non-blocking |
|
| 297 |
+
| `KEYDOWN(key#)` | TRUE/FALSE | Held-key detection, graphics mode only |
|
| 298 |
| `WAITKEY(key#, ...)` | Key value | Blocks until key pressed; `WAITKEY()` = any key |
|
| 299 |
|
| 300 |
+
- **Layout-safe keys:** letters, digits, arrows, Space/Enter/Esc, F-keys, numpad and modifiers are the same on every layout — use these for controls. Main-keyboard punctuation (`+ - = , . /`) depends on the layout: never bind controls to `ASC("+")` or `ASC("-")`; use letters or `KEY_NUMPAD_PLUS#` / `KEY_NUMPAD_MINUS#`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
- Letters always return uppercase codes (`"a"` and `"A"` → `KEY_A#`), in both graphics and console mode.
|
| 302 |
+
- `KEYDOWN` follows the key *label* on the current layout, same as `INKEY`. If no key types a punctuation character without modifiers (e.g. `=` on a Finnish keyboard), `KEYDOWN` of that constant is always FALSE.
|
| 303 |
+
- Numpad Enter = `KEY_ENTER#`.
|
| 304 |
+
- `INKEY` consumes the key: read it once per loop pass (`LET k$ = INKEY`) and compare the variable. A second `INKEY` in the same pass returns 0.
|
| 305 |
+
- Console mode: `INKEY`/`WAITKEY` return the typed character (except letters and special keys); numpad returns the typed digit, not `KEY_NUMPAD*#`.
|
| 306 |
+
|
|
|
|
|
|
|
|
|
|
| 307 |
### Mouse (graphics mode only)
|
| 308 |
`MOUSEX`, `MOUSEY` — cursor position
|
| 309 |
+
`MOUSELEFT`, `MOUSERIGHT`, `MOUSEMIDDLE` — 1 if pressed, 0 otherwise
|
| 310 |
+
`MOUSEHIDE` / `MOUSESHOW` — hide / restore the cursor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
+
### Gamepad (console AND graphics mode)
|
| 313 |
| Function | Returns | Notes |
|
| 314 |
|----------|---------|-------|
|
| 315 |
| `GAMEPADS()` | Number of connected pads | Parentheses optional |
|
|
|
|
| 318 |
| `PADNAME(pad)` | String | e.g. `"PS4 Controller"`, `""` if not connected |
|
| 319 |
| `PADRUMBLE pad, strength, ms` | — (statement) | strength 0.0…1.0, non-blocking, parentheses optional |
|
| 320 |
|
| 321 |
+
- Pad index is **0-based**, max 8 pads. Slots are stable while connected (not re-packed on disconnect). Hot-plug works.
|
| 322 |
+
- **No `SCREEN` needed** — works in console programs too.
|
| 323 |
+
- **Disconnected pad = no input, never an error:** `PADBUTTON` → FALSE, `PADAXIS` → 0, `PADNAME` → `""`. Don't guard every read with `IF GAMEPADS() > 0`; use `GAMEPADS()` only to show a "connect a pad" message.
|
| 324 |
+
- Buttons (Xbox naming): `PAD_A#` `PAD_B#` `PAD_X#` `PAD_Y#`, `PAD_UP#` `PAD_DOWN#` `PAD_LEFT#` `PAD_RIGHT#`, `PAD_LB#` `PAD_RB#`, `PAD_LSTICK#` `PAD_RSTICK#`, `PAD_BACK#` `PAD_START#` `PAD_GUIDE#`, `PAD_MISC#`, `PAD_TOUCHPAD#`. PlayStation: A=Cross, B=Circle, X=Square, Y=Triangle. Raw 0–20 valid (16–19 = Elite paddles); outside → error.
|
| 325 |
+
- Axes: `PAD_LX#` `PAD_LY#` `PAD_RX#` `PAD_RY#` `PAD_LT#` `PAD_RT#`. Raw 0–5; outside → error.
|
| 326 |
+
- **Y axis: negative = up**, same as screen Y. `y$ = y$ + PADAXIS(0, PAD_LY#) * SPEED#` is correct — do not invert.
|
| 327 |
+
- **L2/R2 are triggers, not buttons:** read with `PADAXIS(pad, PAD_LT#)`. Never pass an axis constant to `PADBUTTON` — `PADBUTTON(0, PAD_LT#)` silently reads button 4 (`PAD_BACK#`).
|
| 328 |
+
- For one action per press, keep previous state: `IF now$ = TRUE AND was$ = FALSE THEN ...` then `was$ = now$`.
|
|
|
|
| 329 |
- Stick as digital direction: `IF PADAXIS(0, PAD_LX#) < -0.5 THEN ...`
|
| 330 |
+
- Pad OR keyboard: `IF PADBUTTON(0, PAD_LEFT#) OR KEYDOWN(KEY_LEFT#) THEN dx$ = -1`
|
| 331 |
+
- Many third-party pads identify as PS4/Xbox controllers — normal, mapping is still correct.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
|
| 333 |
---
|
| 334 |
|
| 335 |
## User-Defined Functions
|
| 336 |
|
| 337 |
```basic
|
|
|
|
| 338 |
DEF FN Clamp$(val$, lo$, hi$)
|
| 339 |
IF val$ < lo$ THEN RETURN lo$
|
| 340 |
IF val$ > hi$ THEN RETURN hi$
|
| 341 |
RETURN val$
|
| 342 |
END DEF
|
| 343 |
|
| 344 |
+
PRINT FN Clamp$(5, 1, 10) ' ✓ return value used
|
| 345 |
+
LET v$ = FN Clamp$(15, 0, 10) ' ✓
|
| 346 |
FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
| 347 |
```
|
| 348 |
|
| 349 |
+
- Scope is isolated (see *Critical Rules*). Touching a global array gives: `Global array G$ is not visible inside DEF FN - pass it as a parameter with ASJSON() and rebuild it with ASARRAY()`
|
| 350 |
+
- `DIM` inside a function creates a **fresh, empty, local** array on every call and every recursion level:
|
| 351 |
+
```basic
|
| 352 |
DEF FN Count$(x$)
|
| 353 |
+
DIM t$
|
| 354 |
t$(x$) = 1
|
| 355 |
RETURN LEN(t$())
|
| 356 |
END DEF
|
| 357 |
PRINT FN Count$(1) ' 1
|
| 358 |
PRINT FN Count$(2) ' 1 (not 2)
|
| 359 |
+
```
|
| 360 |
+
- Parameters are passed **by value**
|
|
|
|
| 361 |
- Labels inside functions are local — GOTO/GOSUB cannot jump outside
|
| 362 |
+
- Recursion uses the real call stack, so thousands of levels can overflow it. GOSUB/RETURN uses a separate heap-based stack with no such limit.
|
|
|
|
|
|
|
| 363 |
|
| 364 |
---
|
| 365 |
|
|
|
|
| 369 |
|----------|-------------|
|
| 370 |
| `ASC(s$)` | ASCII code of first char |
|
| 371 |
| `CHR(n)` | Character from ASCII code |
|
| 372 |
+
| `INSTR(s$, search$)` | Position (1-based), 0=not found; case-sensitive |
|
| 373 |
| `INSTR(s$, search$, mode)` | mode: 0=case-insensitive, 1=case-sensitive |
|
|
|
|
| 374 |
| `INVERT(s$)` | Reverse string |
|
| 375 |
| `LCASE(s$)` / `UCASE(s$)` | Lower / upper case |
|
| 376 |
| `LEFT(s$, n)` / `RIGHT(s$, n)` | First/last n chars |
|
|
|
|
| 380 |
| `MID(s$, start, len)` | Substring with length |
|
| 381 |
| `REPEAT(s$, n)` | Repeat string n times |
|
| 382 |
| `REPLACE(s$, a$, b$)` | Replace a$ with b$ in s$ |
|
| 383 |
+
| `SPLIT(arr$, s$, sep$)` | Split into array (keys `0`..`count-1`), returns count. Array is emptied first. `arr$()` also accepted |
|
| 384 |
+
| `SRAND(n)` | Random alphanumeric string of length n. `n = 0` → `""`; **negative n crashes** with an overflow error — never pass an unvalidated length |
|
| 385 |
| `STR(n)` | Number to string |
|
| 386 |
| `VAL(s$)` | String to number |
|
| 387 |
| `SHA256(s$)` | SHA256 hash (64-char hex) |
|
| 388 |
| `BASE64ENCODE(s$)` / `BASE64DECODE(s$)` | Base64 encode/decode |
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
---
|
| 391 |
|
| 392 |
## FSTRING — String Interpolation
|
| 393 |
|
| 394 |
+
`FSTRING(template$)` substitutes `{{-name-}}` placeholders with the value of variables, constants, or array elements.
|
| 395 |
|
| 396 |
```basic
|
| 397 |
LET name$ = "Krisu"
|
|
|
|
| 400 |
' Output: Hello Krisu, level 5
|
| 401 |
```
|
| 402 |
|
| 403 |
+
The triple-character markers `{{-` and `-}}` are deliberately unusual. There is no escape syntax — literal `{{-...-}}` is always parsed as a placeholder.
|
|
|
|
|
|
|
| 404 |
|
| 405 |
| Form | Resolves to |
|
| 406 |
|------|-------------|
|
| 407 |
+
| `{{-var$-}}` | Variable `var$` |
|
| 408 |
+
| `{{-CONST#-}}` | Constant `CONST#` (built-ins like `{{-PI#-}}` work too) |
|
| 409 |
+
| `{{-arr$(0)-}}` | Element at numeric index `0` |
|
| 410 |
+
| `{{-arr$(i$)-}}` | Element at index from variable `i$` |
|
| 411 |
+
| `{{-arr$(KEY#)-}}` | Element at index from constant `KEY#` |
|
| 412 |
+
| `{{-arr$(name)-}}` | Element at literal string key `"name"` (no quotes inside FSTRING) |
|
| 413 |
+
| `{{-arr$(0, i$)-}}` | Multidimensional, mixed literal and variable indices |
|
| 414 |
+
|
| 415 |
+
**Index resolution** — for each comma-separated index, FSTRING checks:
|
|
|
|
|
|
|
|
|
|
| 416 |
1. Ends with `$` or `#` → variable / constant lookup. Halts if undefined.
|
| 417 |
+
2. Parses as a number → numeric index. `arr$(01)` and `arr$(1.0)` both resolve to key `1`.
|
| 418 |
+
3. Otherwise → literal string key.
|
| 419 |
|
| 420 |
+
So `{{-name-}}` (no suffix) is a literal array key, **not** variable `name$`. Always include the suffix.
|
| 421 |
|
| 422 |
+
**Notes:** Whitespace inside placeholders is trimmed. Numbers auto-stringify. FSTRING returns a value and must be used — a bare `FSTRING(...)` statement is an error. Undefined names, missing `-}}`, empty `{{--}}`, malformed or uninitialized array access all halt with a line-numbered message.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
+
**Not supported:** arithmetic, function calls, nested lookups, or quoted literals inside placeholders. Pre-compute into a variable:
|
|
|
|
|
|
|
| 425 |
|
| 426 |
```basic
|
| 427 |
' ❌ WRONG
|
|
|
|
| 436 |
PRINT FSTRING("Total: {{-total$-}}, Name: {{-upper$-}}, Item: {{-arr$(k$)-}}")
|
| 437 |
```
|
| 438 |
|
| 439 |
+
**Full example:**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
|
| 441 |
```basic
|
| 442 |
DIM player$
|
|
|
|
| 445 |
player$("level") = 99
|
| 446 |
|
| 447 |
DIM grid$
|
|
|
|
|
|
|
| 448 |
grid$(1, 0) = "."
|
| 449 |
grid$(1, 1) = "X"
|
| 450 |
|
| 451 |
LET row$ = 1
|
|
|
|
| 452 |
|
| 453 |
PRINT FSTRING("{{-player$(name)-}} the {{-player$(class)-}}, lvl {{-player$(level)-}}")
|
| 454 |
PRINT FSTRING("Row {{-row$-}}: [{{-grid$(row$, 0)-}}{{-grid$(row$, 1)-}}]")
|
|
|
|
| 455 |
END
|
| 456 |
+
' Output:
|
| 457 |
+
' Krisu the Bass, lvl 99
|
| 458 |
+
' Row 1: [.X]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
```
|
| 460 |
|
| 461 |
---
|
|
|
|
| 466 |
|----------|-------------|
|
| 467 |
| `ABS(n)` | Absolute value |
|
| 468 |
| `ATAN(n)` | Arc tangent |
|
| 469 |
+
| `ATAN2(y, x)` | Angle in radians from the positive x-axis to point (x, y) |
|
| 470 |
| `BETWEEN(n, min, max)` | TRUE if min ≤ n ≤ max |
|
| 471 |
+
| `INBETWEEN(n, min, max)` | TRUE if min < n < max (strict) |
|
| 472 |
| `CEIL(n)` / `FLOOR(n)` | Round up / down |
|
| 473 |
| `CINT(n)` | Round to nearest integer |
|
| 474 |
| `CLAMP(n, min, max)` | Constrain n to [min, max] |
|
|
|
|
| 481 |
| `LERP(start, end, t)` | Linear interpolation (t: 0.0–1.0) |
|
| 482 |
| `LOG(n)` | Natural logarithm |
|
| 483 |
| `MAX(a, b)` / `MIN(a, b)` | Larger / smaller of two |
|
| 484 |
+
| `MOD(a, b)` / `a % b` | Remainder (function and operator forms are equivalent) |
|
|
|
|
| 485 |
| `POW(base, exp)` | Power |
|
| 486 |
+
| `RND(n)` | Random integer 0 to n-1 (n > 0) |
|
| 487 |
+
| `RND(0)` | Random float 0.0–1.0 |
|
| 488 |
+
| `ROUND(n)` | Nearest integer, half away from zero (`0.5→1`, `-0.5→-1`) — NOT banker's rounding |
|
| 489 |
| `SGN(n)` | Sign: -1, 0, or 1 |
|
| 490 |
| `SQR(n)` | Square root |
|
| 491 |
|
| 492 |
+
### Fast Trigonometry
|
| 493 |
+
|
| 494 |
+
About 20× faster than `SIN(RAD(x))`, 1-degree precision, ~5.6 KB memory. Use for raycasting, sprite rotation, particle systems — anything calling trig hundreds of times per frame.
|
| 495 |
+
|
| 496 |
+
```basic
|
| 497 |
+
FastTrig(TRUE) ' Enable lookup tables (must call first)
|
| 498 |
+
LET x$ = FastCos(45) ' Degrees, auto-normalized 0–359
|
| 499 |
+
LET y$ = FastSin(90)
|
| 500 |
+
LET r$ = FastRad(180) ' Deg→rad (no FastTrig needed)
|
| 501 |
+
FastTrig(FALSE) ' Free memory
|
| 502 |
+
```
|
| 503 |
|
| 504 |
---
|
| 505 |
|
| 506 |
+
## ISSET
|
| 507 |
|
| 508 |
+
`ISSET(name)` returns `1` if the named variable (`$`) or constant (`#`) is declared, `0` otherwise. The argument is **not evaluated**, so `ISSET(undef$)` safely returns `0`.
|
| 509 |
+
|
| 510 |
+
- **Scalars only.** `ISSET(arr$)` and `ISSET(arr$(0))` always return `0`, never an error.
|
| 511 |
+
- **Bare name only.** Expressions, string literals, numbers or an empty argument (`ISSET(a$ + b$)`, `ISSET("a$")`, `ISSET(42)`, `ISSET()`) error with "invalid parameter".
|
| 512 |
+
- **Suffix is part of the name:** `a$` and `A#` are different names.
|
| 513 |
+
- **`LET name$` without a value still counts as set.** ISSET reports declaration, not "has a meaningful value".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
|
| 515 |
```basic
|
| 516 |
+
IF ISSET(playerName$) = FALSE THEN
|
| 517 |
LET playerName$ = "Anonymous"
|
| 518 |
END IF
|
| 519 |
```
|
|
|
|
| 530 |
FULLSCREEN FALSE ' Windowed
|
| 531 |
```
|
| 532 |
|
| 533 |
+
Classic modes: 1, 7, 13 = 320×200 · 2, 9 = 640×350 · 12 = 640×480.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
|
| 535 |
### Drawing Primitives
|
| 536 |
```basic
|
| 537 |
+
PSET (x, y), color ' Pixel
|
| 538 |
+
LINE (x1,y1)-(x2,y2), color ' Line
|
| 539 |
+
LINE (x1,y1)-(x2,y2), color, B ' Box outline
|
| 540 |
+
LINE (x1,y1)-(x2,y2), color, BF ' Box filled
|
| 541 |
+
CIRCLE (cx,cy), radius, color ' Circle outline
|
| 542 |
+
CIRCLE (cx,cy), radius, color, 1 ' Circle filled
|
| 543 |
+
PAINT (x, y), fillColor, borderColor ' Flood fill
|
| 544 |
+
LET c$ = POINT(x, y) ' Read pixel color
|
| 545 |
+
LET COL# = RGB(r, g, b) ' Create color (0–255 each)
|
| 546 |
```
|
| 547 |
|
| 548 |
+
**Color values:** All drawing primitives (`PSET`, `LINE`, `CIRCLE`, `PAINT`, `DRAWSTRING`, `LOADSHAPE`) accept a palette index 0–15 or an `RGB(r, g, b)` value. Never hand-construct packed integers (e.g. `16711680`) — `RGB()` tags its value internally, and a raw integer is misread as a palette index.
|
|
|
|
|
|
|
| 549 |
|
| 550 |
**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
|
| 551 |
|
|
|
|
|
|
|
| 552 |
### Screen Control
|
| 553 |
```basic
|
| 554 |
+
SCREENLOCK ON ' Start frame (buffer drawing)
|
| 555 |
+
SCREENLOCK OFF ' Present buffer
|
| 556 |
+
VSYNC(TRUE) ' Enable VSync (default) — loop runs at monitor refresh rate
|
| 557 |
VSYNC(FALSE) ' Disable VSync (benchmarking)
|
|
|
|
|
|
|
|
|
|
| 558 |
```
|
| 559 |
|
| 560 |
### Shapes & Images
|
| 561 |
```basic
|
| 562 |
+
LET RECT# = LOADSHAPE("RECTANGLE", w, h, color) ' or "CIRCLE", "TRIANGLE"
|
|
|
|
|
|
|
|
|
|
| 563 |
LET IMG_PLAYER# = LOADIMAGE("player.png") ' PNG (alpha) or BMP
|
| 564 |
+
LET IMG_REMOTE# = LOADIMAGE("https://example.com/a.png") ' Download + load
|
| 565 |
|
| 566 |
' Sprite sheet — sprites indexed 0-based
|
| 567 |
DIM sprites$
|
| 568 |
+
LOADSHEET sprites$, 128, 128, "sheet.png" ' tileW, tileH, file
|
| 569 |
+
MOVESHAPE sprites$(0), x, y
|
| 570 |
|
| 571 |
+
MOVESHAPE RECT#, x, y ' Position
|
|
|
|
|
|
|
|
|
|
| 572 |
ROTATESHAPE RECT#, angle ' Degrees (absolute)
|
| 573 |
SCALESHAPE RECT#, scale ' 1.0 = original size
|
| 574 |
DRAWSHAPE RECT# ' Render to buffer
|
|
|
|
| 576 |
REMOVESHAPE RECT# ' Free memory (always clean up)
|
| 577 |
```
|
| 578 |
|
| 579 |
+
**Anchor point:** `LOADSHAPE` primitives are center-anchored; `LOADIMAGE` images are top-left-anchored.
|
| 580 |
|
| 581 |
+
### Text Rendering (requires SDL2_ttf.dll next to the interpreter)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
|
| 583 |
```basic
|
| 584 |
+
DRAWSTRING "Hello!", 100, 200, WHITE# ' Default font: Arial, 16px
|
| 585 |
+
LOADFONT "comic.ttf", 24 ' Becomes the new default
|
| 586 |
+
LOADFONT ' Reset to Arial 16px
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
```
|
| 588 |
|
| 589 |
+
`DRAWSTRING text, x, y, color` positions the top-left of the text.
|
| 590 |
|
| 591 |
---
|
| 592 |
|
| 593 |
## Sound
|
| 594 |
|
| 595 |
```basic
|
|
|
|
|
|
|
| 596 |
LET SND_JUMP# = LOADSOUND("jump.wav") ' Load (WAV recommended)
|
| 597 |
SOUNDONCE(SND_JUMP#) ' Play once, non-blocking
|
| 598 |
+
SOUNDONCEWAIT(SND_JUMP#) ' Play once, wait for finish
|
| 599 |
+
SOUNDREPEAT(SND_JUMP#) ' Loop continuously
|
| 600 |
+
SOUNDSTOP(SND_JUMP#) ' Stop specific sound
|
| 601 |
SOUNDSTOPALL ' Stop all sounds
|
| 602 |
```
|
| 603 |
|
|
|
|
| 608 |
## File I/O
|
| 609 |
|
| 610 |
```basic
|
| 611 |
+
LET data$ = FILEREAD("file.txt") ' Read as string
|
| 612 |
+
DIM cfg$ : LET cfg$ = FILEREAD("settings.txt") ' Read as key=value array
|
| 613 |
+
FILEWRITE "save.txt", data$ ' Create/overwrite (array → key=value format)
|
| 614 |
+
FILEAPPEND "log.txt", entry$ ' Append
|
| 615 |
+
LET ok$ = FILEEXISTS("file.txt") ' 1=exists, 0=not
|
| 616 |
+
FILEDELETE "temp.dat" ' Delete file
|
| 617 |
DIM files$
|
| 618 |
+
LET n$ = FILELIST(files$, "levels", "*.txt") ' Names into files$(0..n-1), returns n
|
| 619 |
```
|
| 620 |
|
| 621 |
+
**key=value parsing:** When `FILEREAD` assigns to a `DIM`'d array, lines `key=value` become `arr$("key")`; lines starting with `#` are comments. Round-trips with `FILEWRITE`. Good for `.env` files:
|
|
|
|
|
|
|
| 622 |
|
| 623 |
```basic
|
| 624 |
DIM env$
|
| 625 |
+
LET env$ = FILEREAD(".env")
|
| 626 |
LET API_KEY# = env$("OPENAI_API_KEY")
|
| 627 |
```
|
| 628 |
|
| 629 |
+
**FILELIST:** files only (no folders, not recursive), names only (no paths), sorted alphabetically ignoring case, hidden/system files skipped. The array is cleared first. Pattern supports `*` and `?`, default all files. Missing folder → returns `0`. To open a listed file, prepend the folder: `FILEREAD("levels/" + files$(i$))`.
|
| 630 |
+
|
| 631 |
+
**Paths:** Use `/` or `\\` — never a single `\` (escape char). Relative paths are from `PRG_ROOT#`, which already ends with a separator: `PRG_ROOT# + "data.txt"`.
|
|
|
|
|
|
|
|
|
|
| 632 |
|
| 633 |
---
|
| 634 |
|
|
|
|
| 638 |
LET res$ = HTTPGET("https://api.example.com/data")
|
| 639 |
LET res$ = HTTPPOST("https://api.example.com/submit", "{""key"":""val""}")
|
| 640 |
|
| 641 |
+
' Optional headers
|
| 642 |
DIM headers$
|
| 643 |
headers$("Authorization") = "Bearer mytoken"
|
| 644 |
headers$("Content-Type") = "application/json"
|
| 645 |
LET res$ = HTTPGET("https://api.example.com/data", headers$)
|
| 646 |
LET res$ = HTTPPOST("https://api.example.com/data", body$, headers$)
|
| 647 |
|
| 648 |
+
' Optional timeout in seconds, AFTER headers (default 30, 0 = no limit)
|
|
|
|
| 649 |
LET res$ = HTTPPOST("http://localhost:11434/v1/chat/completions", body$, headers$, 120)
|
| 650 |
```
|
| 651 |
|
| 652 |
### Local HTTP server (LISTEN)
|
| 653 |
|
| 654 |
+
Local-only server, typically glue between a static HTML page and a BazzBasic script on the same machine.
|
| 655 |
|
| 656 |
```basic
|
| 657 |
+
STARTLISTEN 8080 ' Bind 127.0.0.1:8080, no admin needed
|
| 658 |
+
STARTLISTEN 8080, 5000 ' Optional timeout in ms
|
| 659 |
+
LET body$ = GETREQUEST() ' POST/PUT/PATCH body or GET query string ("" on timeout)
|
| 660 |
+
SENDRESPONSE "{""status"":""ok""}" ' Must be called or the browser hangs
|
| 661 |
STOPLISTEN
|
| 662 |
```
|
| 663 |
|
| 664 |
+
- **Always pair `GETREQUEST()` with `SENDRESPONSE`.**
|
| 665 |
+
- **Bound to `127.0.0.1` only.** Do not generate code that tries to expose it on a LAN or the internet.
|
| 666 |
+
- **Body or query string only** (no `?`). Headers, method and URL path are not exposed. Parse JSON bodies with `ASARRAY`.
|
| 667 |
+
- **OPTIONS preflight and CORS are automatic.** Don't handle `OPTIONS`; every response carries `Access-Control-Allow-Origin: *`.
|
| 668 |
+
- **One listener at a time.** Call `STOPLISTEN` before another `STARTLISTEN`.
|
| 669 |
+
- **Always 200 OK, always `text/plain`.** To return JSON, put JSON text in the body — browser-side `response.json()` still works.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
|
| 671 |
```basic
|
| 672 |
STARTLISTEN 8080
|
|
|
|
| 674 |
|
| 675 |
LET json$ = GETREQUEST()
|
| 676 |
DIM data$
|
| 677 |
+
LET count$ = ASARRAY(data$, json$)
|
|
|
|
| 678 |
PRINT "Got name: " + data$("name")
|
| 679 |
|
| 680 |
SENDRESPONSE "{""status"":""ok""}"
|
|
|
|
| 686 |
|
| 687 |
## Arrays & JSON
|
| 688 |
|
| 689 |
+
Nested JSON maps to comma-separated keys: `data$("player,name")`, `data$("skills,0")`.
|
| 690 |
|
| 691 |
```basic
|
| 692 |
+
LET json$ = ASJSON(arr$) ' Array → JSON string
|
|
|
|
|
|
|
|
|
|
| 693 |
DIM data$
|
| 694 |
+
LET count$ = ASARRAY(data$, json$) ' JSON string → array, returns element count
|
| 695 |
+
LOADJSON arr$, "file.json" ' Load JSON file
|
| 696 |
+
SAVEJSON arr$, "file.json" ' Save JSON file
|
|
|
|
|
|
|
| 697 |
```
|
| 698 |
|
| 699 |
+
### Passing Arrays to Functions
|
|
|
|
|
|
|
| 700 |
|
| 701 |
+
Serialize with `ASJSON`, pass the string, rebuild inside with `ASARRAY`. The function gets an independent copy — changes inside do not affect the original. Nested keys work normally.
|
| 702 |
|
| 703 |
```basic
|
| 704 |
+
DEF FN ProcessPlayer$(data$)
|
| 705 |
+
DIM arr$
|
| 706 |
+
LET count$ = ASARRAY(arr$, data$)
|
| 707 |
+
RETURN arr$("name") + " score:" + arr$("score")
|
| 708 |
+
END DEF
|
| 709 |
+
|
| 710 |
+
[inits]
|
| 711 |
+
DIM player$
|
| 712 |
+
player$("name") = "Alice"
|
| 713 |
+
player$("score") = 9999
|
| 714 |
+
player$("address,city") = "New York"
|
| 715 |
|
| 716 |
+
[main]
|
| 717 |
+
LET json$ = ASJSON(player$)
|
| 718 |
+
PRINT FN ProcessPlayer$(json$)
|
| 719 |
+
END
|
| 720 |
+
```
|
| 721 |
|
| 722 |
---
|
| 723 |
|
| 724 |
## Date & Time
|
| 725 |
|
| 726 |
```basic
|
| 727 |
+
LET t$ = TIME() ' Default "HH:mm:ss" -> "15:21:22"
|
| 728 |
+
LET t2$ = TIME("dd.MM.yyyy") ' .NET DateTime format -> "04.09.2026"
|
| 729 |
LET t3$ = TIME("dddd") ' -> "Friday"
|
|
|
|
| 730 |
LET start$ = TICKS ' Milliseconds since program start
|
|
|
|
|
|
|
| 731 |
```
|
| 732 |
|
| 733 |
+
**Timing — SLEEP and TICKS do different jobs:**
|
| 734 |
+
- **Frame pacing:** in graphics mode, VSync (on by default) waits at `SCREENLOCK OFF`, limiting the loop to the monitor's refresh rate — usually 60 FPS, but 144 FPS on a 144 Hz monitor. Do NOT add `SLEEP 16` to a graphics loop — together they halve the frame rate.
|
| 735 |
+
- **SLEEP ms:** use for deliberate pauses (title screens, "Game Over" delays) and to keep console loops from using 100% CPU (`SLEEP 10` in an `INKEY` polling loop).
|
| 736 |
+
- **TICKS:** use for measuring time — timers, cooldowns, animation speed, and movement that should stay the same speed on every monitor.
|
| 737 |
|
| 738 |
```basic
|
| 739 |
+
[inits]
|
| 740 |
+
LET running$ = TRUE
|
| 741 |
+
LET lastTick$ = TICKS
|
| 742 |
+
LET delta$
|
| 743 |
+
LET x$ = 0, speed$ = 2 ' several variables in one LET
|
|
|
|
|
|
|
|
|
|
| 744 |
|
| 745 |
+
[main]
|
| 746 |
+
WHILE running$
|
| 747 |
+
delta$ = TICKS - lastTick$
|
| 748 |
+
lastTick$ = TICKS
|
| 749 |
+
x$ = x$ + speed$ * delta$ / 16 ' same speed regardless of frame rate
|
| 750 |
+
GOSUB [sub:draw]
|
| 751 |
+
WEND
|
| 752 |
+
END
|
| 753 |
```
|
| 754 |
|
| 755 |
---
|
|
|
|
| 758 |
|
| 759 |
```basic
|
| 760 |
' bazzbasic.exe myprog.bas arg1 arg2
|
| 761 |
+
PRINT ARGCOUNT ' 2
|
| 762 |
+
PRINT ARGS(0) ' "arg1"
|
| 763 |
+
PRINT ARGS(1) ' "arg2"
|
| 764 |
```
|
| 765 |
|
| 766 |
+
0-based; does not include the interpreter or script name.
|
| 767 |
|
| 768 |
---
|
| 769 |
|
|
|
|
| 779 |
PRINT FN MATHLIB_add$(5, 3)
|
| 780 |
```
|
| 781 |
|
| 782 |
+
- Library functions can read main-program constants (`#`).
|
| 783 |
+
- `.bb` files are **version-locked** to the build that produced them — recompile after upgrading.
|
| 784 |
+
- **No extension fallback:** `INCLUDE "helpers"` does NOT try `helpers.bas`.
|
| 785 |
+
- **Path resolution:** relative to the including file's directory first, then the program's base path.
|
| 786 |
+
- **Circular includes** halt with `Circular INCLUDE detected: <file>`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
|
| 788 |
---
|
| 789 |
|
| 790 |
## Program Structure
|
| 791 |
|
| 792 |
```basic
|
| 793 |
+
' ---- 1. FUNCTIONS (or INCLUDE) ----
|
| 794 |
DEF FN Clamp$(v$, lo$, hi$)
|
| 795 |
IF v$ < lo$ THEN RETURN lo$
|
| 796 |
IF v$ > hi$ THEN RETURN hi$
|
| 797 |
RETURN v$
|
| 798 |
END DEF
|
| 799 |
|
| 800 |
+
' ---- 2. INIT — declare ALL constants & variables here ----
|
|
|
|
| 801 |
[inits]
|
| 802 |
+
LET SCREEN_W# = 640
|
| 803 |
+
LET SCREEN_H# = 480
|
| 804 |
+
LET MAX_SPEED# = 5
|
| 805 |
+
LET PLAYER_COLOR# = RGB(0, 255, 0)
|
| 806 |
|
| 807 |
SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
|
| 808 |
|
|
|
|
| 815 |
WHILE running$
|
| 816 |
IF INKEY = KEY_ESC# THEN running$ = FALSE
|
| 817 |
GOSUB [sub:update]
|
| 818 |
+
GOSUB [sub:draw] ' SCREENLOCK OFF + VSync paces the loop to the monitor refresh rate
|
|
|
|
| 819 |
WEND
|
| 820 |
SOUNDSTOPALL
|
| 821 |
+
END
|
| 822 |
|
| 823 |
+
' ---- 4. SUBROUTINES (or INCLUDE) ----
|
| 824 |
[sub:update]
|
| 825 |
IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED#
|
| 826 |
IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED#
|
|
|
|
| 829 |
[sub:draw]
|
| 830 |
SCREENLOCK ON
|
| 831 |
LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
|
| 832 |
+
CIRCLE (x$, y$), 10, PLAYER_COLOR#, 1
|
| 833 |
SCREENLOCK OFF
|
| 834 |
RETURN
|
| 835 |
```
|
| 836 |
|
| 837 |
+
**Naming conventions:** variables `camelCase$`, constants `UPPER_SNAKE_CASE#`, functions `PascalCase$`, labels `[gameLoop]` for jump targets and `[sub:name]` for subroutines.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
|
| 839 |
---
|
| 840 |
|
| 841 |
+
## IDE
|
| 842 |
|
| 843 |
+
From version 1.6, the IDE (`BazzBasic-IDE.exe`) and interpreter (`BazzBasic.exe`) are separate programs in the same release .zip. Launching the interpreter without arguments tries to open the IDE; if that fails, it prints a message to the console.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 844 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 845 |
| Menu | Items |
|
| 846 |
|------|-------|
|
| 847 |
+
| **File** | New, Open, Save, Save As, Save All, Close Tab, Close All, Restore Session on Startup¹, Print, Exit |
|
| 848 |
+
| **Edit** | Undo, Redo, Cut, Copy, Paste, Select All, Comment Selection, Uncomment Selection |
|
| 849 |
+
| **Search** | Find, Replace |
|
| 850 |
+
| **View** | Tree View¹ (DEF FN functions and labels on the left), Open Console², Open File Browser², Light Mode¹, Dark Mode (experimental)¹, Syntax Coloring¹ (off = monochrome), Take a Screenshot to Clipboard (IDE window only), Zoom In, Zoom Out |
|
| 851 |
+
| **Run** | Run Program (F5), Compile as Exe, Compile as Library (.bb), Path to BazzBasic.exe³ |
|
| 852 |
+
| **Help** | About, Homepage, Online Manual, Beginner's Guide, Rosetta Code, Check for Updates |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 853 |
|
| 854 |
+
¹ Saved to `%AppData%\BazzBasic\ide.json`
|
| 855 |
+
² Opens in the current file's folder
|
| 856 |
+
³ Used if set; otherwise the IDE's own folder, then `PATH`
|
| 857 |
|
| 858 |
+
- Compile commands auto-save the file first.
|
| 859 |
+
- Help-menu links open the URLs listed at the top of this guide.
|
| 860 |
+
- CLI equivalents: `bazzbasic.exe -guide` / `-help` prints the Beginner's Guide URL, `bazzbasic.exe -checkupdates` checks for a newer version.
|
| 861 |
+
- New files get this template:
|
| 862 |
+
```basic
|
| 863 |
+
' BazzBasic version {ver_num}
|
| 864 |
+
' https://ekbass.github.io/BazzBasic/
|
| 865 |
+
```
|
| 866 |
|
| 867 |
+
## Examples
|
|
|
|
|
|
|
| 868 |
|
| 869 |
+
Example programs can be found in the `Examples/` directory (relative to the directory for this skill).
|
| 870 |
+
- Before writing BazzBasic code, review the examples most relevant to the task and follow the practices demonstrated in them (naming conventions, structure, typical idioms).
|
| 871 |
+
- The examples are organized into folders, such as "graphics", "console", "API", "GamePad", etc.
|