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,8 +13,7 @@ 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 |
-
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,26 +21,22 @@ BazzBasic is a BASIC meant for beginners and for small, fun experiments (simple
|
|
| 22 |
|
| 23 |
| Rule | Detail |
|
| 24 |
|------|--------|
|
| 25 |
-
| Variables end with `$` | `name$`, `score$`, `x$`
|
| 26 |
-
| Constants end with `#` | `MAX#`, `PI#`, `TITLE#`
|
| 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 |
-
|
|
| 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 |
-
|
|
| 35 |
-
|
|
|
|
|
| 36 |
| Division always returns float | `10 / 3` → `3.333...` |
|
| 37 |
-
| Division by zero returns `0`
|
| 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 |
|
| 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,51 +53,79 @@ DEF FN doStuff(a, b) DEF FN DoStuff$(a$, b$)
|
|
| 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,
|
| 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 |
-
-
|
| 74 |
-
-
|
| 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 |
-
|
|
|
|
| 87 |
LET name$ = "World"
|
| 88 |
|
| 89 |
[main]
|
| 90 |
PRINT "Hello, " + name$
|
| 91 |
END
|
| 92 |
|
| 93 |
-
'
|
| 94 |
[sub:drawScreen]
|
| 95 |
-
|
| 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 |
-
|
| 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,7 +144,8 @@ LET counter$ +=
|
|
| 121 |
|
| 122 |
Tokens that trigger this: `+ - * / % = <> < <= > >= AND OR += -= *= /= ,`
|
| 123 |
|
| 124 |
-
> `%`
|
|
|
|
| 125 |
|
| 126 |
**Rule 2 — open paren.** Anything inside an unmatched `(` keeps reading until the matching `)`:
|
| 127 |
|
|
@@ -132,90 +156,115 @@ LET dist$ = DISTANCE(
|
|
| 132 |
)
|
| 133 |
```
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
---
|
| 136 |
|
| 137 |
## Variables & Constants
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
Variables
|
| 140 |
-
|
| 141 |
```basic
|
| 142 |
-
LET a$
|
| 143 |
-
LET b$, c$, d$
|
| 144 |
-
LET e$, f$ = "foo", g$ = 10
|
| 145 |
|
| 146 |
-
LET name$ = "Alice"
|
| 147 |
-
LET score$ = 0
|
| 148 |
|
| 149 |
-
LET PI# = 3.14159
|
| 150 |
-
LET TITLE# = "My Game"
|
| 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
|
|
|
|
|
|
|
| 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
|
| 173 |
-
- **Version:** `BBVER#` (current
|
| 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#`
|
| 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
|
| 188 |
matrix$(0, 1) = "A2" ' Multi-dimensional
|
| 189 |
|
| 190 |
DIM sounds$
|
| 191 |
-
sounds$("guns", "shotgun_shoot")
|
| 192 |
-
sounds$("guns", "
|
| 193 |
-
sounds$("
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
PRINT LEN(sounds$()) '
|
| 196 |
-
PRINT ROWCOUNT(sounds$()) ' 2
|
| 197 |
|
| 198 |
DIM car$
|
| 199 |
car$("manufacturer") = "Ford"
|
| 200 |
car$("engine") = "1.6 Eco"
|
|
|
|
| 201 |
|
| 202 |
-
FOR i$ = 0 TO LEN(car$()) - 1 '
|
| 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
|
| 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
-
> `DIM arr$ = value`
|
| 219 |
|
| 220 |
---
|
| 221 |
|
|
@@ -244,10 +293,22 @@ WHILE x$ < 100
|
|
| 244 |
x$ = x$ * 2
|
| 245 |
WEND
|
| 246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
' Labels, GOTO, GOSUB
|
| 248 |
[start]
|
| 249 |
GOSUB [sub:init]
|
| 250 |
-
|
|
|
|
| 251 |
|
| 252 |
[sub:init]
|
| 253 |
LET x$ = 0
|
|
@@ -257,59 +318,77 @@ RETURN
|
|
| 257 |
LET target$ = "[menu]"
|
| 258 |
GOTO target$
|
| 259 |
|
|
|
|
| 260 |
SLEEP 2000 ' Pause for milliseconds
|
| 261 |
END ' Terminate program
|
| 262 |
```
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
---
|
| 267 |
|
| 268 |
## I/O
|
| 269 |
|
| 270 |
| Command | Description |
|
| 271 |
|---------|-------------|
|
| 272 |
-
| `PRINT expr; expr` | `;` = no space, `,` = tab
|
| 273 |
| `PRINT "text";` | Trailing `;` suppresses newline |
|
| 274 |
-
| `INPUT "prompt", var$` | Splits on whitespace/comma
|
| 275 |
| `INPUT "prompt", a$, b$` | Multiple values |
|
| 276 |
| `LINE INPUT "prompt", var$` | Read entire line with spaces |
|
| 277 |
-
| `CLS` | Clear screen
|
| 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
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
-
**SHELL + SQLite.**
|
| 289 |
-
- Always append `2>&1`, or SQL errors disappear silently.
|
| 290 |
-
-
|
| 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
|
| 298 |
| `WAITKEY(key#, ...)` | Key value | Blocks until key pressed; `WAITKEY()` = any key |
|
| 299 |
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
- `
|
| 303 |
-
|
| 304 |
-
|
| 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`,
|
| 310 |
-
`MOUSEHIDE`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
-
### Gamepad (console AND graphics mode)
|
| 313 |
| Function | Returns | Notes |
|
| 314 |
|----------|---------|-------|
|
| 315 |
| `GAMEPADS()` | Number of connected pads | Parentheses optional |
|
|
@@ -318,48 +397,57 @@ Labels may contain almost any printable character. Whitespace is trimmed; everyt
|
|
| 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.
|
| 322 |
-
- **No `SCREEN` needed** —
|
| 323 |
-
- **Disconnected pad = no input, never an error:** `PADBUTTON` → FALSE, `PADAXIS` → 0, `PADNAME` → `""`.
|
| 324 |
-
-
|
| 325 |
-
-
|
| 326 |
-
-
|
| 327 |
-
- **
|
| 328 |
-
-
|
|
|
|
| 329 |
- Stick as digital direction: `IF PADAXIS(0, PAD_LX#) < -0.5 THEN ...`
|
| 330 |
-
-
|
| 331 |
-
- Many third-party pads identify as PS4/Xbox controllers — normal, mapping
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
-
|
| 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 |
-
|
|
|
|
| 361 |
- Labels inside functions are local — GOTO/GOSUB cannot jump outside
|
| 362 |
-
-
|
|
|
|
|
|
|
| 363 |
|
| 364 |
---
|
| 365 |
|
|
@@ -369,8 +457,9 @@ FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
|
| 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,18 +469,24 @@ FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
|
| 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.
|
| 384 |
-
| `SRAND(n)` | Random alphanumeric string of length n
|
| 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,28 +495,39 @@ PRINT FSTRING("Hello {{-name$-}}, level {{-LEVEL#-}}")
|
|
| 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$-}}` |
|
| 408 |
-
| `{{-CONST#-}}` |
|
| 409 |
-
| `{{-arr$(0)-}}` |
|
| 410 |
-
| `{{-arr$(i$)-}}` |
|
| 411 |
-
| `{{-arr$(KEY#)-}}` |
|
| 412 |
-
| `{{-arr$(name)-}}` |
|
| 413 |
-
| `{{-arr$(0, i$)-}}` | Multidimensional, mixed literal and variable indices |
|
| 414 |
-
|
| 415 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
|
| 422 |
-
|
| 423 |
|
| 424 |
-
|
| 425 |
|
| 426 |
```basic
|
| 427 |
' ❌ WRONG
|
|
@@ -436,7 +542,19 @@ LET k$ = arr2$(0)
|
|
| 436 |
PRINT FSTRING("Total: {{-total$-}}, Name: {{-upper$-}}, Item: {{-arr$(k$)-}}")
|
| 437 |
```
|
| 438 |
|
| 439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
|
| 441 |
```basic
|
| 442 |
DIM player$
|
|
@@ -445,17 +563,25 @@ 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 |
-
|
| 457 |
-
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
```
|
| 460 |
|
| 461 |
---
|
|
@@ -466,9 +592,9 @@ END
|
|
| 466 |
|----------|-------------|
|
| 467 |
| `ABS(n)` | Absolute value |
|
| 468 |
| `ATAN(n)` | Arc tangent |
|
| 469 |
-
| `ATAN2(
|
| 470 |
| `BETWEEN(n, min, max)` | TRUE if min ≤ n ≤ max |
|
| 471 |
-
| `INBETWEEN(n, min, max)` | TRUE if min < n < max (
|
| 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,39 +607,47 @@ END
|
|
| 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)`
|
|
|
|
| 485 |
| `POW(base, exp)` | Power |
|
| 486 |
-
| `RND(n)` | Random integer 0 to n-1
|
| 487 |
-
| `RND(0)` |
|
| 488 |
-
| `ROUND(n)` |
|
| 489 |
| `SGN(n)` | Sign: -1, 0, or 1 |
|
| 490 |
| `SQR(n)` | Square root |
|
| 491 |
|
| 492 |
-
###
|
| 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 |
-
##
|
| 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 |
-
|
| 511 |
-
-
|
| 512 |
-
|
| 513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
|
| 515 |
```basic
|
| 516 |
-
IF ISSET(playerName$)
|
| 517 |
LET playerName$ = "Anonymous"
|
| 518 |
END IF
|
| 519 |
```
|
|
@@ -530,45 +664,65 @@ FULLSCREEN TRUE ' Borderless fullscreen (graphics only)
|
|
| 530 |
FULLSCREEN FALSE ' Windowed
|
| 531 |
```
|
| 532 |
|
| 533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
|
| 535 |
### Drawing Primitives
|
| 536 |
```basic
|
| 537 |
-
PSET (x, y), color
|
| 538 |
-
LINE (x1,y1)-(x2,y2), color
|
| 539 |
-
LINE (x1,y1)-(x2,y2), color, B
|
| 540 |
-
LINE (x1,y1)-(x2,y2), color, BF
|
| 541 |
-
CIRCLE (cx,cy), radius, color
|
| 542 |
-
CIRCLE (cx,cy), radius, color, 1
|
| 543 |
-
PAINT (x, y), fillColor, borderColor
|
| 544 |
-
LET c$ = POINT(x, y)
|
| 545 |
-
LET
|
| 546 |
```
|
| 547 |
|
| 548 |
-
**
|
|
|
|
|
|
|
| 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 '
|
| 555 |
-
SCREENLOCK OFF ' Present buffer
|
| 556 |
-
VSYNC(TRUE) ' Enable VSync (default
|
| 557 |
VSYNC(FALSE) ' Disable VSync (benchmarking)
|
|
|
|
|
|
|
|
|
|
| 558 |
```
|
| 559 |
|
| 560 |
### Shapes & Images
|
| 561 |
```basic
|
| 562 |
-
|
|
|
|
|
|
|
|
|
|
| 563 |
LET IMG_PLAYER# = LOADIMAGE("player.png") ' PNG (alpha) or BMP
|
| 564 |
-
LET IMG_REMOTE# = LOADIMAGE("https://example.com/a.png")
|
| 565 |
|
| 566 |
' Sprite sheet — sprites indexed 0-based
|
| 567 |
DIM sprites$
|
| 568 |
-
LOADSHEET sprites$, 128, 128, "sheet.png"
|
| 569 |
-
MOVESHAPE sprites$(0), x, y
|
| 570 |
|
| 571 |
-
|
|
|
|
|
|
|
|
|
|
| 572 |
ROTATESHAPE RECT#, angle ' Degrees (absolute)
|
| 573 |
SCALESHAPE RECT#, scale ' 1.0 = original size
|
| 574 |
DRAWSHAPE RECT# ' Render to buffer
|
|
@@ -576,28 +730,39 @@ SHOWSHAPE RECT# / HIDESHAPE RECT# ' Toggle visibility
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
|
| 583 |
```basic
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
```
|
| 588 |
|
| 589 |
-
`DRAWSTRING
|
| 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#)
|
| 599 |
-
SOUNDREPEAT(SND_JUMP#)
|
| 600 |
-
SOUNDSTOP(SND_JUMP#)
|
| 601 |
SOUNDSTOPALL ' Stop all sounds
|
| 602 |
```
|
| 603 |
|
|
@@ -608,27 +773,32 @@ Load all sounds at startup. Call `SOUNDSTOPALL` before `END`.
|
|
| 608 |
## File I/O
|
| 609 |
|
| 610 |
```basic
|
| 611 |
-
LET data$ =
|
| 612 |
-
DIM cfg$ : LET cfg$ =
|
| 613 |
-
FILEWRITE "save.txt", data$
|
| 614 |
-
FILEAPPEND "log.txt", entry$
|
| 615 |
-
LET ok$ = FILEEXISTS("file.txt")
|
| 616 |
-
FILEDELETE "temp.dat"
|
| 617 |
DIM files$
|
| 618 |
-
LET n$ = FILELIST(files$, "levels", "*.txt") '
|
| 619 |
```
|
| 620 |
|
| 621 |
-
**
|
|
|
|
|
|
|
| 622 |
|
| 623 |
```basic
|
| 624 |
DIM env$
|
| 625 |
-
LET env$ =
|
| 626 |
LET API_KEY# = env$("OPENAI_API_KEY")
|
| 627 |
```
|
| 628 |
|
| 629 |
-
**
|
| 630 |
-
|
| 631 |
-
|
|
|
|
|
|
|
|
|
|
| 632 |
|
| 633 |
---
|
| 634 |
|
|
@@ -638,35 +808,41 @@ LET API_KEY# = env$("OPENAI_API_KEY")
|
|
| 638 |
LET res$ = HTTPGET("https://api.example.com/data")
|
| 639 |
LET res$ = HTTPPOST("https://api.example.com/submit", "{""key"":""val""}")
|
| 640 |
|
| 641 |
-
'
|
| 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 |
-
'
|
|
|
|
| 649 |
LET res$ = HTTPPOST("http://localhost:11434/v1/chat/completions", body$, headers$, 120)
|
| 650 |
```
|
| 651 |
|
| 652 |
### Local HTTP server (LISTEN)
|
| 653 |
|
| 654 |
-
|
| 655 |
|
| 656 |
```basic
|
| 657 |
-
STARTLISTEN 8080 '
|
| 658 |
-
STARTLISTEN 8080, 5000 '
|
| 659 |
-
LET body$ = GETREQUEST() ' POST/PUT/PATCH body or GET query string ("" on timeout)
|
| 660 |
-
SENDRESPONSE "{""status"":""ok""}" '
|
| 661 |
STOPLISTEN
|
| 662 |
```
|
| 663 |
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
- **
|
| 667 |
-
- **
|
| 668 |
-
- **
|
| 669 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
|
| 671 |
```basic
|
| 672 |
STARTLISTEN 8080
|
|
@@ -674,7 +850,8 @@ PRINT "Waiting for browser..."
|
|
| 674 |
|
| 675 |
LET json$ = GETREQUEST()
|
| 676 |
DIM data$
|
| 677 |
-
LET
|
|
|
|
| 678 |
PRINT "Got name: " + data$("name")
|
| 679 |
|
| 680 |
SENDRESPONSE "{""status"":""ok""}"
|
|
@@ -686,70 +863,66 @@ END
|
|
| 686 |
|
| 687 |
## Arrays & JSON
|
| 688 |
|
| 689 |
-
Nested JSON maps to comma-separated keys: `data$("player,name")`, `data$("skills,0")`
|
| 690 |
|
| 691 |
```basic
|
| 692 |
-
|
|
|
|
|
|
|
|
|
|
| 693 |
DIM data$
|
| 694 |
-
LET count$ = ASARRAY(data$, json$)
|
| 695 |
-
LOADJSON arr$, "file.json" ' Load JSON file
|
| 696 |
-
SAVEJSON arr$, "file.json" ' Save JSON file
|
| 697 |
-
```
|
| 698 |
|
| 699 |
-
|
|
|
|
|
|
|
|
|
|
| 700 |
|
| 701 |
-
|
| 702 |
|
| 703 |
-
|
| 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 |
-
|
| 711 |
-
DIM player$
|
| 712 |
-
player$("name") = "Alice"
|
| 713 |
-
player$("score") = 9999
|
| 714 |
-
player$("address,city") = "New York"
|
| 715 |
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
|
|
|
|
|
|
| 720 |
```
|
| 721 |
|
|
|
|
|
|
|
| 722 |
---
|
| 723 |
|
| 724 |
## Date & Time
|
| 725 |
|
| 726 |
```basic
|
| 727 |
-
LET t$
|
| 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 |
-
|
| 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 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
LET delta$
|
| 743 |
-
|
|
|
|
|
|
|
|
|
|
| 744 |
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 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,12 +931,12 @@ END
|
|
| 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,30 +952,60 @@ INCLUDE "MathLib.bb" ' Load compiled library
|
|
| 779 |
PRINT FN MATHLIB_add$(5, 3)
|
| 780 |
```
|
| 781 |
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
- **No extension fallback
|
| 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
|
|
|
|
| 801 |
[inits]
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
LET PLAYER_COLOR# = RGB(0, 255, 0)
|
| 806 |
|
| 807 |
SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
|
| 808 |
|
|
@@ -815,12 +1018,13 @@ END DEF
|
|
| 815 |
WHILE running$
|
| 816 |
IF INKEY = KEY_ESC# THEN running$ = FALSE
|
| 817 |
GOSUB [sub:update]
|
| 818 |
-
GOSUB [sub:draw]
|
|
|
|
| 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,37 +1033,139 @@ RETURN
|
|
| 829 |
[sub:draw]
|
| 830 |
SCREENLOCK ON
|
| 831 |
LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
|
| 832 |
-
CIRCLE (x$, y$), 10,
|
| 833 |
SCREENLOCK OFF
|
| 834 |
RETURN
|
| 835 |
```
|
| 836 |
|
| 837 |
-
**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
|
| 839 |
---
|
| 840 |
|
| 841 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 842 |
|
| 843 |
-
|
| 844 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 845 |
| Menu | Items |
|
| 846 |
|------|-------|
|
| 847 |
-
| **File** | New, Open, Save, Save As, Save All, Close Tab, Close All, Restore Session on Startup
|
| 848 |
-
| **Edit** | Undo, Redo, Cut, Copy, Paste, Select All, Comment Selection, Uncomment Selection |
|
| 849 |
-
| **Search** | Find, Replace |
|
| 850 |
-
| **View** | Tree View
|
| 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 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
-
|
| 860 |
-
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
**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 |
+
**Communities:** https://ekbass.github.io/BazzBasic/communities.html
|
|
|
|
| 17 |
|
| 18 |
---
|
| 19 |
|
|
|
|
| 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 |
+
| Functions defined **before** they are called | Put at top or INCLUDE |
|
|
|
|
| 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 |
+
| Arrays **cannot** be passed to functions directly | Pass individual elements, or serialize to JSON string — see *Passing Arrays to Functions* section |
|
| 33 |
+
| Case-insensitive | `PRINT`, `print`, `Print` all work |
|
| 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` (no error) | Guard with `IF b$ = 0 THEN ...` if needed |
|
| 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 | Don't use `_`, `\`, or `&` — lexer continues automatically after operators or open `(` |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
---
|
| 42 |
|
|
|
|
| 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:" + STR(x$), 10, 10, RGB(255,255,255)
|
| 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 — see Line Continuation
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
+
**Two more traps that don't fit the table:**
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
- Inside `DEF FN` you can read `#` constants from the outer scope but **not** `$` variables or global arrays. Pass values as parameters.
|
| 66 |
+
- Arrays cannot be passed to a function directly, and a function cannot see global arrays. Serialize with `ASJSON()` and rebuild inside the function with `ASARRAY()` — see *Passing Arrays to Functions* below.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
---
|
| 69 |
|
| 70 |
## Minimal Valid Program
|
| 71 |
|
| 72 |
```basic
|
| 73 |
+
' Suggested style to use [subs]
|
| 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 |
+
' other subs after END'
|
| 82 |
[sub:drawScreen]
|
| 83 |
+
' draw
|
| 84 |
RETURN
|
| 85 |
```
|
| 86 |
|
| 87 |
+
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.
|
| 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 |
+
BazzBasic has **no line-continuation character**. Do not generate `_` (VBA), `\` (Python), or `&` (other dialects). The lexer figures out continuation automatically using two rules.
|
| 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 |
|
| 145 |
Tokens that trigger this: `+ - * / % = <> < <= > >= AND OR += -= *= /= ,`
|
| 146 |
|
| 147 |
+
> `%` 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.
|
| 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 |
)
|
| 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 require suffix "$". Constants require suffix "#".
|
| 178 |
+
The suffix does not define data type — only "#" indicates immutability.
|
| 179 |
```basic
|
| 180 |
+
LET a$ ' Declare variable without value
|
| 181 |
+
LET b$, c$, d$ ' Multiple variable declarations without value
|
| 182 |
+
LET e$, f$ = "foo", g$ = 10 ' Multiple variable declaration, e$ stays empty, f$ and g$ gets values
|
| 183 |
|
| 184 |
+
LET name$ = "Alice" ' String variable
|
| 185 |
+
LET score$ = 0 ' Numeric variable
|
| 186 |
|
| 187 |
+
LET PI# = 3.14159 ' Constant (immutable)
|
| 188 |
+
LET TITLE# = "My Game" ' String constant
|
| 189 |
```
|
| 190 |
|
| 191 |
+
**Compound assignment operators** (variables only — **not** allowed with `#` constants):
|
| 192 |
|
| 193 |
```basic
|
| 194 |
LET x$ = 1
|
| 195 |
+
x$ += 5 ' add
|
| 196 |
+
x$ -= 3 ' subtract
|
| 197 |
+
x$ *= 2 ' multiply
|
| 198 |
+
x$ /= 4 ' divide
|
| 199 |
LET s$ = "Hello"
|
| 200 |
+
s$ += " World" ' string concatenation
|
| 201 |
```
|
| 202 |
|
| 203 |
+
**Scope:** All main-code variables share one scope (IF, FOR, and WHILE do NOT create new 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, not a separate type. `IF x$ = 1` and `IF x$ = TRUE` are identical.
|
| 213 |
+
- **Math:** `PI#`, `HPI#` (π/2 = 90°), `QPI#` (π/4 = 45°), `TAU#` (2π = 360°), `EULER#` (e) — `#` suffix required
|
| 214 |
+
- **System:** `PRG_ROOT#` (program base directory path)
|
| 215 |
+
- **Version:** `BBVER#` (returns current version of BazzBasic, ie: "1.6")
|
| 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#`/`_MINUS#`/`_MUL#`/`_DIV#`/`_DOT#`, `KEY_LSHIFT#`, `KEY_LCTRL#`, etc. — see *Keyboard Input*
|
| 217 |
+
- **Gamepad:** buttons `PAD_A#`…`PAD_Y#`, `PAD_UP#`/`_DOWN#`/`_LEFT#`/`_RIGHT#`, `PAD_LB#`, `PAD_RB#`, `PAD_START#`, `PAD_BACK#` etc.; axes `PAD_LX#`, `PAD_LY#`, `PAD_RX#`, `PAD_RY#`, `PAD_LT#`, `PAD_RT#` — see *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 are associative, insertion-ordered.
|
| 230 |
matrix$(0, 1) = "A2" ' Multi-dimensional
|
| 231 |
|
| 232 |
DIM sounds$
|
| 233 |
+
sounds$("guns", "shotgun_shoot") = "shoot_shotgun.wav"
|
| 234 |
+
sounds$("guns", "shotgun_reload") = "reload_shotgun.wav"
|
| 235 |
+
sounds$("guns", "ak47_shoot") = "shoot_ak47.wav"
|
| 236 |
+
sounds$("guns", "ak47_reload") = "reload_ak47.wav"
|
| 237 |
+
sounds$("food", "ham_eat") = "eat_ham.wav"
|
| 238 |
|
| 239 |
+
PRINT LEN(sounds$()) ' 5 - total elements across both "guns" and "food" groups
|
| 240 |
+
PRINT ROWCOUNT(sounds$()) ' 2, "guns" & "food"
|
| 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 ' Iterate an associative array: LEN + ARRKEY
|
| 248 |
+
LET key$ = ARRKEY(car$(), i$) ' No FOREACH in BazzBasic - this is the idiom
|
| 249 |
PRINT key$; " = "; car$(key$)
|
| 250 |
NEXT i$
|
| 251 |
```
|
| 252 |
|
| 253 |
| Function/Command | Description |
|
| 254 |
|-----------------|-------------|
|
| 255 |
+
| `LEN(arr$())` | Total element count (LEN counts all nested elements across all dimensions) |
|
| 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. Pair with `LEN` to loop over string-keyed arrays with `FOR/NEXT` or `WHILE/WEND`. Errors on out-of-range index. |
|
| 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$` as `COPYARRAY`. |
|
| 262 |
+
|
| 263 |
+
**JOIN** Matching keys from src2$ overwrite src1$ at the same level
|
| 264 |
+
|
| 265 |
+
**Always check with `HASKEY` before reading uninitialized elements.**
|
| 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 |
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 |
+
' Avoid jumping into the middle of logical blocks (e.g. inside IF/WHILE)
|
| 311 |
+
GOTO [start]
|
| 312 |
|
| 313 |
[sub:init]
|
| 314 |
LET x$ = 0
|
|
|
|
| 318 |
LET target$ = "[menu]"
|
| 319 |
GOTO target$
|
| 320 |
|
| 321 |
+
' Other
|
| 322 |
SLEEP 2000 ' Pause for milliseconds
|
| 323 |
END ' Terminate program
|
| 324 |
```
|
| 325 |
+
**Note:** Labels are case-insensitive and may contain almost any printable character.
|
| 326 |
+
Whitespace is trimmed. Everything between "[" and "]" is treated as the label name.
|
|
|
|
| 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 (0–15 palette) |
|
|
|
|
| 343 |
| `SHELL("cmd")` | Run shell command, returns output |
|
| 344 |
| `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
|
| 345 |
|
| 346 |
+
' ; prints without spacing
|
| 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 |
+
**Escape sequences in strings:** `\"` `\n` `\t` `\\`
|
| 352 |
|
| 353 |
+
**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:
|
| 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; KEYDOWN only works in graphics mode |
|
| 363 |
| `WAITKEY(key#, ...)` | Key value | Blocks until key pressed; `WAITKEY()` = any key |
|
| 364 |
|
| 365 |
+
**Keyboard layouts.** Letters (`KEY_A#`…`KEY_Z#`), digits, arrows, Space/Enter/Esc, F-keys,
|
| 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`: `KEYDOWN(KEY_A#)` is the key that types "a" (on AZERTY that is a different physical key than on QWERTY). If no key types a punctuation character without modifiers (e.g. "=" on a Finnish keyboard), `KEYDOWN` of that constant is always FALSE.
|
| 373 |
+
- Numpad: `KEY_NUMPAD0#`…`KEY_NUMPAD9#`, `KEY_NUMPAD_PLUS#`, `KEY_NUMPAD_MINUS#`,
|
| 374 |
+
`KEY_NUMPAD_MUL#`, `KEY_NUMPAD_DIV#`, `KEY_NUMPAD_DOT#` (graphics mode). Numpad Enter = `KEY_ENTER#`.
|
| 375 |
+
- INKEY consumes the key: read it once per loop pass into a variable (`LET k$ = INKEY`)
|
| 376 |
+
and compare the variable. Two `INKEY` calls in one pass → the second returns 0.
|
| 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 — return 1 if pressed, 0 otherwise
|
| 383 |
+
`MOUSEHIDE` — hide the mouse cursor (graphics screen only)
|
| 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 |
| `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. A pad keeps its number while connected (stable slots, not re-packed on disconnect).
|
| 401 |
+
- **No `SCREEN` needed** — unlike `KEYDOWN`/mouse, gamepad functions work in console programs too.
|
| 402 |
+
- **Disconnected pad = no input, never an error:** `PADBUTTON` → FALSE, `PADAXIS` → 0, `PADNAME` → `""`. Do not generate guard code like `IF GAMEPADS() > 0 THEN` around every read; use `GAMEPADS()` only to show a "connect a pad" message.
|
| 403 |
+
- Hot-plug works: pads connected while the program runs are picked up automatically.
|
| 404 |
+
- Button constants (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 numbers 0–20 are valid (16–19 = Elite paddles); outside that → error.
|
| 405 |
+
- Axis constants: `PAD_LX#` `PAD_LY#` `PAD_RX#` `PAD_RY#` `PAD_LT#` `PAD_RT#`. Raw 0–5; outside → error.
|
| 406 |
+
- **Y axis: negative = up**, same direction as screen Y. So `y$ = y$ + PADAXIS(0, PAD_LY#) * SPEED#` moves correctly — do not invert it.
|
| 407 |
+
- **L2/R2 are triggers, not buttons.** Read them with `PADAXIS(pad, PAD_LT#)` / `PADAXIS(pad, PAD_RT#)`. Never pass an axis constant to `PADBUTTON`: constants are plain numbers, so `PADBUTTON(0, PAD_LT#)` silently reads button 4 (= `PAD_BACK#`) with no error.
|
| 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 |
+
- Typical game input = pad OR keyboard: `IF PADBUTTON(0, PAD_LEFT#) OR KEYDOWN(KEY_LEFT#) THEN dx$ = -1`
|
| 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) ' ✓ OK — return value used
|
| 430 |
+
LET v$ = FN Clamp$(15, 0, 10) ' ✓ OK
|
| 431 |
FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
| 432 |
```
|
| 433 |
|
| 434 |
+
- Isolated scope: no access to global `$` variables or global arrays, only global constants (`#`). Using a global array inside a function is an error: `Global array G$ is not visible inside DEF FN - pass it as a parameter with ASJSON() and rebuild it with ASARRAY()`
|
| 435 |
+
- **Arrays inside functions:** `DIM` inside a function always creates a **fresh, empty, local** array on every call (and on every recursion level). Local arrays do not survive between calls:
|
| 436 |
+
```basic
|
| 437 |
DEF FN Count$(x$)
|
| 438 |
+
DIM t$ ' new empty array on every call
|
| 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 |
+
(In v1.4c and older, arrays `DIM`'d in a function kept their contents between calls, and functions could accidentally reach global arrays by name.)
|
| 446 |
+
- Parameters passed **by value**
|
| 447 |
- Labels inside functions are local — GOTO/GOSUB cannot jump outside
|
| 448 |
+
- 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.
|
| 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 |
|----------|-------------|
|
| 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 by default |
|
| 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 |
| `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. The array is emptied first, so re-splitting a shorter string leaves no old elements. `arr$()` also accepted as first argument |
|
| 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 inside a template string with the value of variables, constants, or array elements. Preferred over long `+` concatenation chains.
|
| 490 |
|
| 491 |
```basic
|
| 492 |
LET name$ = "Krisu"
|
|
|
|
| 495 |
' Output: Hello Krisu, level 5
|
| 496 |
```
|
| 497 |
|
| 498 |
+
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.
|
| 499 |
+
|
| 500 |
+
### Placeholder forms
|
| 501 |
|
| 502 |
| Form | Resolves to |
|
| 503 |
|------|-------------|
|
| 504 |
+
| `{{-var$-}}` | Value of variable `var$` |
|
| 505 |
+
| `{{-CONST#-}}` | Value of constant `CONST#` |
|
| 506 |
+
| `{{-arr$(0)-}}` | Array element at numeric index `0` |
|
| 507 |
+
| `{{-arr$(i$)-}}` | Array element at index taken from variable `i$` |
|
| 508 |
+
| `{{-arr$(KEY#)-}}` | Array element at index taken from constant `KEY#` |
|
| 509 |
+
| `{{-arr$(name)-}}` | Array element at literal string key `"name"` (no quotes inside FSTRING) |
|
| 510 |
+
| `{{-arr$(0, i$)-}}` | Multidimensional element, mixed literal and variable indices |
|
| 511 |
+
|
| 512 |
+
### Index resolution rule (array access)
|
| 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 (`0`, `1.5`, `-3`) → numeric index. `arr$(01)` and `arr$(1.0)` both resolve to key `1`.
|
| 518 |
+
3. Otherwise → literal string key. This is what lets `{{-player$(name)-}}` read what was stored with `player$("name") = ...`.
|
| 519 |
+
|
| 520 |
+
### Notes
|
| 521 |
|
| 522 |
+
- Whitespace inside placeholders is trimmed: `{{- name$ -}}` ≡ `{{-name$-}}`.
|
| 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 |
+
### Not supported (intentional)
|
| 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 |
PRINT FSTRING("Total: {{-total$-}}, Name: {{-upper$-}}, Item: {{-arr$(k$)-}}")
|
| 543 |
```
|
| 544 |
|
| 545 |
+
### Common AI mistakes with FSTRING
|
| 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 |
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 |
+
Output:
|
| 581 |
+
```
|
| 582 |
+
Krisu the Bass, lvl 99
|
| 583 |
+
Row 1: [.X]
|
| 584 |
+
Pi is roughly 3.14
|
| 585 |
```
|
| 586 |
|
| 587 |
---
|
|
|
|
| 592 |
|----------|-------------|
|
| 593 |
| `ABS(n)` | Absolute value |
|
| 594 |
| `ATAN(n)` | Arc tangent |
|
| 595 |
+
| `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 |
|
| 596 |
| `BETWEEN(n, min, max)` | TRUE if min ≤ n ≤ max |
|
| 597 |
+
| `INBETWEEN(n, min, max)` | TRUE if min < n < max (strictly between, not equal) |
|
| 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 |
| `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 if n > 0 |
|
| 614 |
+
| `RND(0)` | Float between 0.0 and 1.0 (IE: 0.5841907423666761) |
|
| 615 |
+
| `ROUND(n)` | Rounds to nearest integer, half rounds away from zero (`0.5→1`, `-0.5→-1`) — NOT banker's rounding |
|
| 616 |
| `SGN(n)` | Sign: -1, 0, or 1 |
|
| 617 |
| `SQR(n)` | Square root |
|
| 618 |
|
| 619 |
+
**Math constants:** `PI#`, `HPI#` (PI/2), `QPI#` (PI/4), `TAU#` (PI*2), `EULER#`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 620 |
|
| 621 |
---
|
| 622 |
|
| 623 |
+
## Variable Functions
|
|
|
|
|
|
|
| 624 |
|
| 625 |
+
| Function | Description |
|
| 626 |
+
|----------|-------------|
|
| 627 |
+
| `ISSET(name)` | `1` if the named variable (`$`) or constant (`#`) is declared, `0` otherwise. Argument is **not evaluated** — `ISSET(undef$)` safely returns `0`. |
|
| 628 |
+
|
| 629 |
+
`ISSET` is the only language-introspection function and it has tight rules:
|
| 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 NOT ISSET(playerName$) THEN
|
| 651 |
LET playerName$ = "Anonymous"
|
| 652 |
END IF
|
| 653 |
```
|
|
|
|
| 664 |
FULLSCREEN FALSE ' Windowed
|
| 665 |
```
|
| 666 |
|
| 667 |
+
| Mode | Resolution |
|
| 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 ' Pixel
|
| 679 |
+
LINE (x1,y1)-(x2,y2), color ' Line
|
| 680 |
+
LINE (x1,y1)-(x2,y2), color, B ' Box outline
|
| 681 |
+
LINE (x1,y1)-(x2,y2), color, BF ' Box filled (FAST — use instead of CLS)
|
| 682 |
+
CIRCLE (cx,cy), radius, color ' Circle outline
|
| 683 |
+
CIRCLE (cx,cy), radius, color, 1 ' Circle filled
|
| 684 |
+
PAINT (x, y), fillColor, borderColor ' Flood fill
|
| 685 |
+
LET c$ = POINT(x, y) ' Read pixel color
|
| 686 |
+
LET col$ = RGB(r, g, b) ' Create color (0–255 each)
|
| 687 |
```
|
| 688 |
|
| 689 |
+
**LINE corners:** `(x2, y2)` is inclusive in all forms (line, `B`, `BF`), and box corners may be in any order. `LINE (10,10)-(12,12), c, BF` fills 3×3 pixels; a box exactly `w` pixels wide ends at `x + w - 1`. (In v1.4c and older, `B`/`BF` excluded the second corner.)
|
| 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 ' Buffer drawing (start frame)
|
| 700 |
+
SCREENLOCK OFF ' Present buffer (end frame)
|
| 701 |
+
VSYNC(TRUE) ' Enable VSync (default, ~60 FPS)
|
| 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 |
+
' Create shape
|
| 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") ' Download + load
|
| 716 |
|
| 717 |
' Sprite sheet — sprites indexed 0-based
|
| 718 |
DIM sprites$
|
| 719 |
+
LOADSHEET sprites$, 128, 128, "sheet.png" ' tileW, tileH, file
|
| 720 |
+
MOVESHAPE sprites$(0), x, y ' sprites$(0) = first sprite
|
| 721 |
|
| 722 |
+
' Transform
|
| 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 |
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 |
+
DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
|
| 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. 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.
|
| 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#) ' Play once, wait for finish
|
| 764 |
+
SOUNDREPEAT(SND_JUMP#) ' Loop continuously
|
| 765 |
+
SOUNDSTOP(SND_JUMP#) ' Stop specific sound
|
| 766 |
SOUNDSTOPALL ' Stop all sounds
|
| 767 |
```
|
| 768 |
|
|
|
|
| 773 |
## File I/O
|
| 774 |
|
| 775 |
```basic
|
| 776 |
+
LET data$ = FileRead("file.txt") ' Read as string
|
| 777 |
+
DIM cfg$ : LET cfg$ = FileRead("settings.txt") ' Read as key=value array
|
| 778 |
+
FILEWRITE "save.txt", data$ ' Create/overwrite
|
| 779 |
+
FILEAPPEND "log.txt", entry$ ' Append
|
| 780 |
+
LET ok$ = FILEEXISTS("file.txt") ' 1=exists, 0=not
|
| 781 |
+
FILEDELETE "temp.dat" ' Delete file
|
| 782 |
DIM files$
|
| 783 |
+
LET n$ = FILELIST(files$, "levels", "*.txt") ' File names into files$(0..n-1), returns n
|
| 784 |
```
|
| 785 |
|
| 786 |
+
**FILELIST:** `FILELIST(arr$, folder$ [, pattern$])` lists files only (no folders, not recursive), names only (no paths), sorted alphabetically ignoring case. The array is cleared first. `pattern$` supports `*` and `?`, default all files. Hidden/system files are skipped. Missing folder → returns `0`. To open a listed file, prepend the folder: `FILEREAD("levels/" + files$(i$))`. Added in v1.5.
|
| 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$ = FileRead(".env")
|
| 793 |
LET API_KEY# = env$("OPENAI_API_KEY")
|
| 794 |
```
|
| 795 |
|
| 796 |
+
**Paths:** Use `/` or `\\` — never single `\` (it's an escape char). Relative paths are from `PRG_ROOT#`.
|
| 797 |
+
`PRG_ROOT#` already ends with a directory separator — concatenate directly, don't add your own `/`:
|
| 798 |
+
```basic
|
| 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 |
LET res$ = HTTPGET("https://api.example.com/data")
|
| 809 |
LET res$ = HTTPPOST("https://api.example.com/submit", "{""key"":""val""}")
|
| 810 |
|
| 811 |
+
' With headers (optional)
|
| 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 |
+
' With timeout in seconds (optional, comes AFTER headers; default 30, 0 = no limit)
|
| 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 |
+
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.
|
| 826 |
|
| 827 |
```basic
|
| 828 |
+
STARTLISTEN 8080 ' bind 127.0.0.1:8080, no admin needed
|
| 829 |
+
STARTLISTEN 8080, 5000 ' optional timeout in ms
|
| 830 |
+
LET body$ = GETREQUEST() ' POST/PUT/PATCH body, or GET query string ("" on timeout)
|
| 831 |
+
SENDRESPONSE "{""status"":""ok""}" ' must be called or browser hangs
|
| 832 |
STOPLISTEN
|
| 833 |
```
|
| 834 |
|
| 835 |
+
Important rules:
|
| 836 |
+
|
| 837 |
+
- **Always pair `GETREQUEST()` with `SENDRESPONSE`.** The browser is waiting on the response. Forgetting `SENDRESPONSE` makes the page hang.
|
| 838 |
+
- **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.
|
| 839 |
+
- **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$)`.
|
| 840 |
+
- **OPTIONS preflight is automatic.** Do NOT write code that handles `OPTIONS` — it is consumed silently and never reaches user code.
|
| 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 |
|
| 851 |
LET json$ = GETREQUEST()
|
| 852 |
DIM data$
|
| 853 |
+
LET data$ = ASARRAY(json$)
|
| 854 |
+
|
| 855 |
PRINT "Got name: " + data$("name")
|
| 856 |
|
| 857 |
SENDRESPONSE "{""status"":""ok""}"
|
|
|
|
| 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 (an empty array gives "{}")
|
| 870 |
+
LET json$ = ASJSON(arr$)
|
| 871 |
+
|
| 872 |
+
' JSON string → array (returns element count)
|
| 873 |
DIM data$
|
| 874 |
+
LET count$ = ASARRAY(data$, json$)
|
|
|
|
|
|
|
|
|
|
| 875 |
|
| 876 |
+
' Load/save JSON files
|
| 877 |
+
LOADJSON arr$, "file.json"
|
| 878 |
+
SAVEJSON arr$, "file.json"
|
| 879 |
+
```
|
| 880 |
|
| 881 |
+
---
|
| 882 |
|
| 883 |
+
## Fast Trigonometry
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
|
| 885 |
+
~20× faster than `SIN(RAD(x))`, 1-degree precision. Uses ~5.6 KB memory.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 886 |
|
| 887 |
+
```basic
|
| 888 |
+
FastTrig(TRUE) ' Enable lookup tables (must call first)
|
| 889 |
+
LET x$ = FastCos(45) ' Degrees, auto-normalized 0–359
|
| 890 |
+
LET y$ = FastSin(90)
|
| 891 |
+
LET r$ = FastRad(180) ' Deg→rad (no FastTrig needed)
|
| 892 |
+
FastTrig(FALSE) ' Free memory
|
| 893 |
```
|
| 894 |
|
| 895 |
+
Use for raycasting, sprite rotation, particle systems, any high-freq trig.
|
| 896 |
+
|
| 897 |
---
|
| 898 |
|
| 899 |
## Date & Time
|
| 900 |
|
| 901 |
```basic
|
| 902 |
+
LET t$ = TIME() ' Current time, default format "HH:mm:ss" -> "15:21:22"
|
| 903 |
+
LET t2$ = TIME("dd.MM.yyyy") ' .NET DateTime format string -> "04.09.2026"
|
| 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 |
+
`TICKS` is the standard way to do frame-independent (delta-time) movement in a game loop — prefer it over counting fixed `SLEEP` increments.
|
|
|
|
|
|
|
|
|
|
| 912 |
|
| 913 |
```basic
|
| 914 |
+
' ✅ Preferred: frame-independent movement
|
| 915 |
+
LET lastTick$ = TICKS
|
| 916 |
+
WHILE running$
|
| 917 |
+
LET delta$ = TICKS - lastTick$
|
| 918 |
+
lastTick$ = TICKS
|
| 919 |
+
x$ = x$ + speed$ * delta$ / 16 ' normalize to ~60 FPS baseline
|
| 920 |
+
GOSUB [sub:draw]
|
| 921 |
+
WEND
|
| 922 |
|
| 923 |
+
' ❌ Avoid: fixed SLEEP without delta — speed varies with actual frame rate
|
| 924 |
+
SLEEP 16
|
| 925 |
+
x$ = x$ + speed$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 926 |
```
|
| 927 |
|
| 928 |
---
|
|
|
|
| 931 |
|
| 932 |
```basic
|
| 933 |
' bazzbasic.exe myprog.bas arg1 arg2
|
| 934 |
+
PRINT ARGCOUNT ' number of args (2 in this example)
|
| 935 |
+
PRINT ARGS(0) ' first arg → "arg1"
|
| 936 |
+
PRINT ARGS(1) ' second arg → "arg2"
|
| 937 |
```
|
| 938 |
|
| 939 |
+
`ARGCOUNT` and `ARGS(n)` are 0-based; ARGS does not include the interpreter or script name.
|
| 940 |
|
| 941 |
---
|
| 942 |
|
|
|
|
| 952 |
PRINT FN MATHLIB_add$(5, 3)
|
| 953 |
```
|
| 954 |
|
| 955 |
+
Library functions can read main-program constants (`#`). `.bb` files are version-locked.
|
| 956 |
+
|
| 957 |
+
- **No extension fallback.** `INCLUDE "helpers"` does NOT try `helpers.bas` automatically — give the exact filename, extension included.
|
| 958 |
+
- **Path resolution order:** relative to the *including file's own directory* first, then relative to the program's base path.
|
| 959 |
+
- **Circular includes are detected** and halt with `Circular INCLUDE detected: <file>`.
|
| 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 "functions.bas/bb") ----
|
| 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 (declare ALL constants & variables here, not inside loops) ----
|
| 1004 |
+
' Performance: variables declared outside loops avoid repeated existence checks.
|
| 1005 |
[inits]
|
| 1006 |
+
LET SCREEN_W# = 640
|
| 1007 |
+
LET SCREEN_H# = 480
|
| 1008 |
+
LET MAX_SPEED# = 5
|
|
|
|
| 1009 |
|
| 1010 |
SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
|
| 1011 |
|
|
|
|
| 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 ' place at the end of main program so BazzBasic wont fall to subs in runtime
|
| 1026 |
|
| 1027 |
+
' ---- 4. SUBROUTINES (or INCLUDE "subs.bas") ----
|
| 1028 |
[sub:update]
|
| 1029 |
IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED#
|
| 1030 |
IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED#
|
|
|
|
| 1033 |
[sub:draw]
|
| 1034 |
SCREENLOCK ON
|
| 1035 |
LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF
|
| 1036 |
+
CIRCLE (x$, y$), 10, RGB(0, 255, 0), 1
|
| 1037 |
SCREENLOCK OFF
|
| 1038 |
RETURN
|
| 1039 |
```
|
| 1040 |
|
| 1041 |
+
**Key conventions:**
|
| 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 |
+
## Performance Tips
|
| 1050 |
+
|
| 1051 |
+
- `LINE (0,0)-(W,H), 0, BF` to clear — much faster than `CLS`
|
| 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 (Ctrl+N), Open (Ctrl+O), Save (Ctrl+S), Save As (Ctrl+Shift+S), Save All, Close Tab (Ctrl+W), Close All, Restore Session on Startup (check mark), Print (Ctrl+P), Exit (Alt+F4) |
|
| 1116 |
+
| **Edit** | Undo (Ctrl+Z), Redo (Ctrl+Y), Cut (Ctrl+X), Copy (Ctrl+C), Paste (Ctrl+V), Select All (Ctrl+A), Comment Selection (Ctrl+Q), Uncomment Selection (Ctrl+Shift+Q) |
|
| 1117 |
+
| **Search** | Find (Ctrl+F), Replace (Ctrl+H) |
|
| 1118 |
+
| **View** | Tree View (check mark), Open Console, Open File Browser, Light Mode, Dark Mode (experimental), Take Screenshot to Clipboard, Zoom In (Ctrl++), Zoom Out (Ctrl+-) |
|
| 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 |
+
### Beginner's Guide
|
| 1157 |
+
- **IDE:** Menu → **Help** → **Beginner's Guide** — opens `https://github.com/EkBass/BazzBasic-Beginners-Guide/releases` in default browser
|
| 1158 |
+
- **CLI:** `bazzbasic.exe -guide` or `bazzbasic.exe -help` — prints URL to terminal
|
| 1159 |
+
|
| 1160 |
+
### Online Manual and Rosetta Code
|
| 1161 |
+
- **IDE:** Menu → **Help** → **Online Manual** — opens `https://ekbass.github.io/BazzBasic/manual/#/` in default browser
|
| 1162 |
+
- **IDE:** Menu → **Help** → **Rosetta Code** — opens `https://rosettacode.org/wiki/Category:BazzBasic` in default browser
|
| 1163 |
+
- No CLI equivalents
|
| 1164 |
+
|
| 1165 |
+
### Check for Updates
|
| 1166 |
+
- **IDE:** Menu → **Help** → **Check for Updates...** — IDE reports if a newer version is available
|
| 1167 |
+
- **CLI:** `bazzbasic.exe -checkupdates`
|
| 1168 |
+
|
| 1169 |
+
### Compile via IDE
|
| 1170 |
+
- **Menu → Run → Compile as Exe** — compiles open file to standalone `.exe` (auto-saves first)
|
| 1171 |
+
- **Menu → Run → Compile as Library (.bb)** — compiles open file as reusable `.bb` library (auto-saves first)
|