text
stringlengths
0
595
# METADATA:
**Name:** BazzBasic-AI-guide.txt
**Description:** BazzBasic BASIC interpreter language reference for AI. Use BazzBasic to write, debug, or teach code.
**File extensions:*** ".bas"*, *".bb"*
**Version:** This guide is written for BazzBasic version 1.2 and is updated 07.04.26 (ddmmyy)
**URL:** This guide is stored and updated at https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
# END METADATA
---
## BazzBasic details
**Version:** 1.2
**Author:** Kristian Virtanen (EkBass)
**Platform:** Windows x64
**License:** MIT
## BazzBasic www-references
**Homepage:** https://ekbass.github.io/BazzBasic/
**GitHub:** https://github.com/EkBass/BazzBasic
**Manual:** https://ekbass.github.io/BazzBasic/manual/#/
**Common examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples
**Rosetta Code:** https://rosettacode.org/wiki/Category:BazzBasic
**Rosetta-Code examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples/rosetta-code
---
## ⚠️ Critical Rules — Read First
| Rule | Detail |
|------|--------|
| Every variable must be introduced with LET exactly once before any use | LET <var> |
| Variables end with `$` | `name$`, `score$`, `x$` |
| Variables must describe purpose | no x$, tmp$, a$ unless loop index |
| 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` |
| Avoid GOTO | Supported only for historical reasons |
| 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 | Pass individual elements by value |
| Case-insensitive | `PRINT`, `print`, `Print` all work |
| `+` operator does both add and concatenate | `"Hi" + " " + name$` |
| Division always returns float | `10 / 3` → `3.333...` |
### Common AI Mistakes
- forgetting LET
- using LET inside subs (wastes computing time, prefer [inits] section)
- calling function before definition
- not using return value from FN (if not other chance, use temp$ to get it)
- passing arrays to functions
- mixing $ and #
- using LET on subs or loops
- forgots to use SCREENLOCK/SCREENUNLOCK
- Does not read: ## Performance Tips
---
## For context from the author:
**About:** BazzBasic is built around one simple idea: starting programming should feel nice and even fun. Ease of learning, comfort of exploration and small but important moments of success. Just like the classic BASICs of decades past, but with a fresh and modern feel.
**Story:** Although over the years, as my own skills have grown, I have moved on to more versatile and modern languages, BASIC has always been something that has been fun to try out many different things with. Sometimes it's great to just make a simple adventure game again, a lottery machine, a quiz, or even just those...
*Maybe one day you will move on to another programming language, but then BazzBasic will have succeeded in doing what it was intended for: To arouse your curiosity.*
- Kristian Virtanen (EkBass), author of BazzBasic
## Variables & Constants
```basic
' variables
LET a$ ' Declare without value
LET name$ = "Alice" ' String variable
LET score$ = 0 ' Numeric variable
LET x$, y$, z$ = 10 ' Multiple declaration
' x$ & y$ has value of 0 while z$ has 10
' constants
LET TITLE# = "My Game" ' String constant
LET_VER# = 1.2 ' Numeric constant
```
**Scope:** All main-code variables share one scope (even inside IF blocks).
`DEF FN` functions are fully isolated — only global constants (`#`) accessible inside.
**Comparison:** `"123" = 123` is TRUE (cross-type), but keep types consistent for speed.
### Built-in Constants
- **Boolean:** `TRUE`, `FALSE`
- **Math:** `PI`, `HPI` (π/2 = 90°), `QPI` (π/4 = 45°), `TAU` (2π = 360°), `EULER` (e)
- **System:** `PRG_ROOT#` (program base directory path), `BBVER#` (interpreter version as text, e.g. `"1.1"`)
- **Keyboard:** `KEY_ESC#`, `KEY_ENTER#`, `KEY_SPACE#`, `KEY_UP#`, `KEY_DOWN#`, `KEY_LEFT#`, `KEY_RIGHT#`, `KEY_F1#`…`KEY_F12#`, `KEY_A#`…`KEY_Z#`, `KEY_0#`…`KEY_9#`, `KEY_LSHIFT#`, `KEY_LCTRL#`, etc.
---
## Arrays
```basic
DIM scores$ ' Declare (required before use)