text
stringlengths
0
721
---
name: bazzbasic
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 questi...
doc. date: 30.04.2026 (dd.mm.yyyy)
filename: BazzBasic-AI-guide-ddmmyyyyX.txt (ddmmyyyy = date of last update) (X is small alphabet "abcd..." presenting daily version incase two versions are released in same day)
IE:
BazzBasic-AI-Guide30042026.txt ' version released 30th April 2026
BazzBasic-AI-Guide30042026b.txt ' version released 30th April 2026, second in same date
---
# BazzBasic Language Reference
**Version:** 1.3b | **Author:** Kristian Virtanen (EkBass) | **Platform:** Windows x64
**Homepage:** https://ekbass.github.io/BazzBasic/
**GitHub:** https://github.com/EkBass/BazzBasic
**Manual:** https://ekbass.github.io/BazzBasic/manual/#/
**Examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples
**Rosetta Code:** https://rosettacode.org/wiki/Category:BazzBasic
**Rosetta Code solutions:** https://github.com/EkBass/BazzBasic/tree/main/Examples/rosetta-code
**BazzBasic-AI-Guide:** https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
**BazzBasic Beginner's Guide:** https://github.com/EkBass/BazzBasic-Beginners-Guide/releases
**Communities:** https://ekbass.github.io/BazzBasic/communities.html
---
## Critical Rules Read First
| Rule | Detail |
|------|--------|
| Variables end with `$` | `name$`, `score$`, `x$` |
| Constants end with `#` | `MAX#`, `PI#`, `TITLE#` |
| Arrays declared with `DIM`, end with `$` | `DIM items$` |
| First use of variable requires `LET` | `LET x$ = 0` after that `x$ = x$ + 1` |
| FOR and INPUT auto-declare, no LET needed | `FOR i$ = 1 TO 10` |
| Functions defined **before** they are called | Put at top or INCLUDE |
| Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
| Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
| Arrays **cannot** be passed to functions directly | Pass individual elements, or serialize to JSON string see *Passing Arrays to Functions* section |
| Case-insensitive | `PRINT`, `print`, `Print` all work |
| `+` operator does both add and concatenate | `"Hi" + " " + name$` |
| Division always returns float | `10 / 3` → `3.333...` |
| Division by zero returns `0` (no error) | Guard with `IF b$ = 0 THEN ...` if needed |
| No integer-division operator | Use `INT(a / b)`, `FLOOR(a / b)`, or `CINT(a / b)` |
| Errors halt the program | No `TRY`/`CATCH` or `ON ERROR` line-numbered message printed |
---
## Common AI Mistakes (avoid these)
These are the patterns LLMs most often produce when extrapolating from QBASIC, FreeBASIC, or VB. None of them are valid BazzBasic.
```basic
' WRONG ' CORRECT
LET x = 5 LET x$ = 5
LET MAX = 10 LET MAX# = 10
score$ = 0 ' first use LET score$ = 0
DEF FN doStuff(a, b) DEF FN DoStuff$(a$, b$)
FN MyFunc$(5) ' return ignored LET v$ = FN MyFunc$(5)
LET handle$ = LOADIMAGE("x.png") LET HANDLE# = LOADIMAGE("x.png")
CLS ' in graphics mode LINE (0,0)-(W,H), 0, BF
PRINT "x:", x$ ' in graphics mode DRAWSTRING "x:" + STR(x$), 10, 10, RGB(255,255,255)
FSTRING("Hi {{name$}}") ' Python-style FSTRING("Hi {{-name$-}}") ' triple-char markers
ISSET(arr$(0)) ' expecting error ' returns 0 silently ISSET only sees scalars
LET x$ = a$ + _ ' VBA continuation LET x$ = a$ + ' just leave the operator
LET x$ = a$ + \ ' Python continuation LET x$ = a$ + ' or open a paren see Line Continuation
```
**Two more traps that don't fit the table:**
- Inside `DEF FN` you can read `#` constants from the outer scope but **not** `$` variables. Pass them as parameters.
- Arrays cannot be passed to a function. Serialize with `ASJSON()` and rebuild inside the function with `ASARRAY()` see *Passing Arrays to Functions* below.
---
## Minimal Valid Program
```basic
[inits]
LET name$ = "World"
[main]
PRINT "Hello, " + name$
END
```
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.
---
## When Generating BazzBasic Code
- Always declare variables with `LET` on first use; subsequent uses don't need it
- Always include the `$` (variable) or `#` (constant) suffix
- Place `DEF FN` definitions at the top of the file or via `INCLUDE`
- Store every `LOADIMAGE` / `LOADSOUND` / `LOADSHAPE` handle as a `#` constant
- In graphics mode, prefer `LINE (0,0)-(W,H), 0, BF` over `CLS`, and `DRAWSTRING` over `PRINT`
- Wrap each frame's drawing in `SCREENLOCK ON` / `SCREENLOCK OFF`