BazzBasic
BazzBasic is a BASIC interpreter built to work with the .NET 10 Framework.
It supports many of the features of BASIC interpreters from the 80s, but also offers something modern.
Development
So far, EkBass has been responsible for the development of BazzBasic.
BazzBasic is released under the open source MIT license.
Its source code is available and visible to everyone in the project’s GitHub repository.
Currently, the development work is done in the Windows 11 operating system, but with quite a bit of effort it can also be translated to Linux or MacOS.
Offline Manual
You can download this manual in HTML format to your own computer.
Download BazzBasic-Manual-HTML.zip
Main functionalities
Most familiar BASIC features work either completely or almost completely as users of traditional BASIC languages are used to using them.
User-Defined Functions
With or without recursion.
DEF FN factorial$(n$)
IF n$ <= 1 THEN
RETURN 1
END IF
RETURN n$ * FN factorial$(n$ - 1)
END DEF
PRINT FN factorial$(5) ' Output: 120
PRINT FN factorial$(10) ' Output: 3628800SDL2 Graphics
BazzBasic offers a reasonable sampling of SDL2 features.
If your program uses graphic features, SDL2.dll must be in the same directory. This does not apply to console-only programs.
Sounds
BazzBasic includes a sound system built on SDL2_mixer, supporting audio playback with both background and blocking modes.
See Sound Commands
Source Control
With the INCLUDE function, you can split the source code into different files and folders or generate tokenized libraries.
See Preprocessor or Generating libraries
Data types
Unlike many traditional BASIC interpreters, which required strong typing and often separated different data types with suffixes such as $ or %, BazzBasic copes smoothly with untyped data.
Typeless Variables and Constants
Variables automatically hold either numbers or strings:
LET num$ = 42 ' Number
LET text$ = "Hello" ' String
LET mixed$ = "123" ' String (quoted)
LET MY_CONST# = "Foo" ' String constant
LET MY_CONST2# = 1 + 2 ' numerical constantArrays
BazzBasic arrays are fully dynamic and support numeric, string, or mixed indexing.
DIM MyArray$
MyArray$("name") = "John Smith"
MyArray$("age") = 42
See Arrays
Getting Started
More Resources
BazzBasic size
Currently, BazzBasic requires about 70 megabytes + SDL2.dll
PublishTrimmed=true would reduce its size, but thorough testing is needed first.
BazzBasic includes .NET 10 assemblies during compilation, which affects the file size.
.NET 10, although a bit bulky, still offers compatibility far into the future.,
Contact
Author of BazzBasic is Kristian Virtanen.
Email: krisu.virtanen@gmail.com
Url: https://github.com/EkBass/BazzBasic
License
BazzBasic is released under MIT license:
MIT License
Copyright (c) 2026 Kristian Virtanen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Installation
Download binary
- Download BazzBasic binary from GitHub Releases.
- Extract the “.zip” package to a folder of your choice.
What’s in the package
| File | What it is |
|---|---|
| BazzBasic.exe | The interpreter. Runs and compiles your .bas files.
Used from the command line, from other editors and by the IDE. |
| BazzBasic-IDE.exe | The BazzBasic code editor (IDE). |
| SDL2.dll, SDL2_mixer.dll, SDL2_ttf.dll | Graphics, sound and fonts. Needed by the interpreter. |
| _runtimes-x64_ | Scintilla.dll and Lexilla.dll. Needed by the IDE. |
| Examples, extras | Example programs and syntax highlighting files for other editors. |
Keep the files together in the same folder.
Since version 1.6 the IDE and the interpreter are two separate programs. Earlier, BazzBasic.exe was both. Nothing changes in how you use them: double-clicking BazzBasic.exe still opens the IDE, and all commands work as before.
If you only use another editor or the command line, you can leave out BazzBasic-IDE.exe and the runtimes folder.
Firewall issues
Since BazzBasic is built around .NET 10 and it is still a fairly recent project, Windows Firewall or third-party security programs may give a warning about it the first time you use it.
However, by switching to the GitHub release and providing the correct metadata during the compilation phase, these warnings can be reduced in the future.
The truth is, however, that open source projects that use .NET platforms will always suffer from this problem to some extent.
Run BazzBasic IDE
- Browse to folder where you extracted BazzBasic.
- Double-click BazzBasic-IDE.exe. Double-clicking BazzBasic.exe opens the IDE too.
- The IDE which comes with BazzBasic is very basic and simple.
In order you to run your BazzBasic code with the IDE, you must save your file first and then press F5 to run it.
The IDE runs your programs with BazzBasic.exe from its own folder. See IDE Usage for how to use another copy.
Use external IDE
- BazzBasic syntax highlighting is also available for notepad++, Geany and Visual Studio Code.
- Get config files for syntax support from here.
- Adjust your editor to launch bazzbasic.exe <filename.bas>
Use with terminal
- bazzbasic.exe without arguments opens the IDE (BazzBasic-IDE.exe in the same folder). If the IDE is not there, it shows the command line usage.
- bazzbasic.exe <filename.bas> runs your BazzBasic code
- bazzbasic.exe -exe <filename.bas> generates an executable from filename.bas
- bazzbasic.exe -lib <filename.bas> generates a tokenized library from filename.bas
- More options: More CLI features
Source
- BazzBasic source code is released under MIT license and it is available at github
- Repository is a Visual Studio 2026 solution with two projects: BazzBasic.csproj (interpreter) and IDE-IDE.csproj (IDE).
- build.bat builds both into bin-windows-x64.
IDE Usage
BazzBasic includes a simple development environment (IDE), BazzBasic-IDE.exe.
Since version 1.6 the IDE is a separate program from the interpreter (BazzBasic.exe). The IDE is the editor; when you run or compile a program, it starts BazzBasic.exe to do the work. Keep both in the same folder.
Menu change (after v1.4c): The old Edit menu (Find, Replace) was renamed to Search, and a new Edit menu was added with Undo, Redo, Cut, Copy, Paste and Select All. A new View menu switches between Light and Dark Mode. The Help menu also gained links to the online manual and Rosetta Code.
If your IDE still shows Find and Replace under Edit, you are running an older version. Everything else works the same way.
Starting the IDE
Double-click BazzBasic-IDE.exe.
Running bazzbasic.exe without any arguments (or
double-clicking it) also opens the IDE, as in earlier versions: it
starts BazzBasic-IDE.exe from the same folder.
Which BazzBasic.exe the IDE uses
Run Program (F5), Compile as Exe and Compile as Library use the
interpreter, BazzBasic.exe. The IDE looks for it in this
order:
- The path set in Run → Path to BazzBasic.exe…
- The IDE’s own folder.
- The folders in the
PATHenvironment variable (see Running BazzBasic from anywhere).
With the release package nothing needs to be set:
BazzBasic.exe is in the same folder as the IDE.
Editor Features
- Syntax highlighting for BazzBasic keywords
- Line numbers for easy navigation
- Multiple tabs for working with several files
- Predictive Mode: a list of matching reserved words opens while typing (View → Predictive Mode, Ctrl+Space)
Keyboard Shortcuts & Menu Map
| Menu | Shortcut | Action | CLI option |
|---|---|---|---|
| File | Ctrl+N | New file | none |
| File | Ctrl+O | Open file | none |
| File | Ctrl+S | Save file | none |
| File | Ctrl+Shift+S | Save As | none |
| File | none | Save All[13] | none |
| File | Ctrl+W | Close tab | none |
| File | none | Close All[14] | none |
| File | none | Restore Session on Startup[6] | none |
| File | Ctrl+P | Print[9] | none |
| File | Alt + F4 | Exit | none |
| Edit | Ctrl+Z | Undo | none |
| Edit | Ctrl+Y | Redo | none |
| Edit | Ctrl+X | Cut | none |
| Edit | Ctrl+C | Copy | none |
| Edit | Ctrl+V | Paste | none |
| Edit | Ctrl+A | Select All | none |
| Edit | Ctrl+Q | Comment Selection[10] | none |
| Edit | Ctrl+Shift+Q | Uncomment Selection[12] | none |
| Search | Ctrl+F | Find | none |
| Search | Ctrl+H | Replace | none |
| View | none | Tree View[15] | none |
| View | Ctrl+Space | Predictive Mode[19] | none |
| View | none | Open Console[7] | none |
| View | none | Open File Browser[7] | none |
| View | none | Light Mode[4] | none |
| View | none | Dark Mode (experimental)[4] | none |
| View | none | Syntax Coloring | none |
| View | none | Take Screenshot to Clipboard[5] | none |
| View | Ctrl++ | Zoom In[11] | none |
| View | Ctrl+- | Zoom Out[11] | none |
| Run | F5 | Run Program | bazzbasic.exe file.bas |
| Run | none | Compile as Exe | bazzbasic.exe -exe file.bas |
| Run | none | Compile as Library (.bb) | bazzbasic.exe -lib file.bas |
| Run | none | Path to BazzBasic.exe…[16] | none |
| Help | none | About | bazzbasic.exe -v |
| Help | none | Homepage[8] | none |
| Help | none | Online Manual[1] | none |
| Help | none | Beginner’s Guide[2] | bazzbasic.exe -guide |
| Help | none | Rosetta Code[3] | none |
| Help | none | Autocheck Updates on Startup[17] | none |
| Help | none | Check For Updates[18] | bazzbasic.exe -checkupdate |
[1] Opens the online manual in
default browser.
[2] Opens BazzBasic-Beginners-Guide/releases
in default browser.
[3] Opens the BazzBasic
category on Rosetta Code in default browser.
[4] The choice is saved to
%AppData%\BazzBasic\ide.json and restored when the IDE
starts. Dark Mode is experimental: the Find/Replace dialog, message
boxes and the empty area next to the editor tabs stay light.
[5] Copies an image of the IDE window to the clipboard.
Paste it with Ctrl+V. No file is saved. When asking for help, prefer
sharing the code as text (Ctrl+A, Ctrl+C, Ctrl+V): others can then copy
and run it.
[6] When checked, the IDE reopens the files that were
open when it was last closed. Only saved files are restored; Untitled
tabs are not. Files that no longer exist are skipped and listed in a
message. The setting is saved to
%AppData%\BazzBasic\ide.json.
[7] Opens a command prompt (Open Console) or Windows
File Explorer (Open File Browser) in the folder of the file in the
active tab. For an unsaved file, the IDE’s own folder is used.
[8] Opens the BazzBasic homepage in
default browser.
[9] Prints the file in the active tab with syntax
highlighting, on a white background also in Dark Mode. To get a PDF,
choose Microsoft Print to PDF as the printer.
[10] Adds the comment mark ' to the start
of every selected line. Without a selection, the line with the cursor is
commented. A line where the selection only touches the very beginning is
left out. The whole change is one Undo step (Ctrl+Z). Useful for
disabling several lines at once, since BazzBasic has no multi-line
comments.
[11] Makes the editor text larger or smaller in the
active tab. Works with the +/- keys on both the main keyboard and the
numeric keypad.
[12] Removes the comment mark ' from the
start of every selected line: ' text and 'text
both become text. The mark is also found after indentation,
and the indentation is kept. Lines without a comment mark, and
REM comments, are left as they are. Selection and Undo work
as in Comment Selection.
[13] Saves every tab that has unsaved changes. For an
Untitled tab, the Save As dialog opens and that tab is shown so you can
see which file it is for. Cancelling the dialog skips only that
file.
[14] Closes all tabs. For each tab with unsaved changes
you are asked whether to save it. Cancel stops Close
All and keeps the remaining tabs open. When all tabs are closed, a new
empty Untitled tab is opened.
[15] When checked, a panel on the left lists the
functions (DEF FN) and labels ([label]) of the
file in the active tab. Click an item to jump to that line. The list
updates shortly after you stop typing. Functions and labels from
INCLUDE files are not listed. Drag the panel edge to change
its width. The on/off choice and the width are saved to
%AppData%\BazzBasic\ide.json.
[16] Chooses which BazzBasic.exe is used
by Run Program and the Compile commands. Leave the field empty
(Clear) to let the IDE find it automatically: first in
the IDE’s own folder, then in the folders listed in the
PATH environment variable. A path you set always comes
first. The dialog shows which file is currently used and where it was
found. If the interpreter cannot be found, Run and Compile tell you and
offer to open this dialog. The setting is saved to
%AppData%\BazzBasic\ide.json. [17] When
checked, the IDE checks GitHub for a newer BazzBasic release when it
starts, at most once a day. It stays quiet unless a new version is
available; then a message shows the new version and the download link.
The on/off choice and the time of the last check are saved to
%AppData%\BazzBasic\ide.json.
[18] Checks GitHub for a newer release now and always
shows the result, even when you are already running the latest version.
A manual check also counts as the day’s check for Autocheck Updates on
Startup. [19] When checked (on by default), a list of
matching reserved words opens while you type in code, after 3 letters —
not inside a comment (' / REM) or a string.
Tab inserts the chosen word in capitals;
Enter closes the list and makes a new line without
inserting the word; Esc closes the list.
Ctrl+Space opens the list by hand, even when the mode
is off or nothing is typed yet — short words like PI#,
IF, TO appear only this way. The list offers
the built-in constants with # (PI#,
HPI#, QPI#, TAU#,
EULER#, PHI#, GRAV#,
GRAV_E#, AU#, BBVER#,
BBBUILD#, PRG_ROOT#,
BLACK#…TRANSPARENT#), not KEY_* /
PAD_*# constants or your own functions, labels or
variables. In Dark Mode the list uses the editor colours. The on/off
choice is saved to %AppData%\BazzBasic\ide.json
(PredictiveMode).
Closing the IDE
If any tab has unsaved changes when you close the IDE, you are asked whether to save each one. Choose Cancel to keep the IDE open.
The IDE remembers its window size and position, and whether it was maximized, and opens the same way next time. If it was last on a screen that is no longer connected, it opens centered on the main screen.
Running Programs
Press F5 to run the current program. The IDE runs it
with BazzBasic.exe, and a console window opens showing the
output.
When the program ends normally, the console window closes. If the program stops on an error, the window stays open and shows the error with its line number. Press any key to close it.
Creating Standalone Executables
BazzBasic can package your BASIC program into a standalone .exe file.
Usage
bazzbasic.exe -exe yourprogram.bas
This creates yourprogram.exe in the same folder as the .bas file. In the IDE, use Run → Compile as Exe.
Size
The packaged exe is a copy of the BazzBasic interpreter with your program inside, so it is about 15 MB regardless of how short your program is.
Before version 1.6 the interpreter and the IDE were the same program, and packaged programs were about 111 MB. Since 1.6 the IDE is a separate program and is not included in your packaged exe.
No .NET installation needed
The packaged exe contains the .NET runtime it needs. The target machine does not need .NET installed.
Required Files for Distribution
| File | Required | Purpose |
|---|---|---|
| yourprogram.exe | Yes | Your packaged program |
| SDL2.dll | Yes | Graphics and input |
| SDL2_mixer.dll | If sound is used | Audio |
| SDL2_ttf.dll | If fonts are used | TrueType fonts |
| *.bb | If libraries are used | Compiled libraries (never embedded in the exe) |
BazzBasic-IDE.exe and the runtimes folder
are not needed: they belong to the IDE only.
Your assets:
| File | Required | Purpose |
|---|---|---|
| .png, .bmp | If used | Image files |
| .wav, .mp3 | If used | Sound files |
| *.ttf | If used | Font files |
Minimal Distribution
mygame/
├── yourprogram.exe
└── SDL2.dll
Distribution with Assets recommendation
mygame/
├── yourprogram.exe
├── SDL2.dll
├── SDL2_mixer.dll
├── SDL2_ttf.dll
├── images/
│ ├── player.png
│ └── enemy.png
└── sounds/
├── shoot.wav
└── music.mp3
Where to Find SDL2.dll
Binary download:
The SDL2 dll files are in the same folder as bazzbasic.exe.
If you build from the source:
After running build.bat, they are in:
BazzBasic\bin\Release\net10.0-windows\win-x64\publish\
Copy them alongside your packaged exe.
Console Window
The standalone exe runs with a console window visible. This is intentional for showing error messages.
Notes
- The packaged exe contains the full BazzBasic interpreter, but not the IDE
- File paths in your BASIC code are relative to the exe location
- INCLUDE “file.bas” files are processed at packaging time and embedded in the exe; INCLUDE “lib.bb” libraries are NOT embedded - the .bb must be distributed next to the exe (see below)
- After an error, the packaged exe exits with code 1
- Command-line arguments work like with the interpreter:
prog.exe arg1 arg2-> ARGCOUNT = 2, ARGS(0) = “arg1”
Creating Libraries
BazzBasic supports pre-compiled libraries (.bb files)
for code reuse. Libraries contain tokenized functions that load faster
than source files and use automatic namespace prefixes to prevent naming
conflicts.
What is a Library?
A library is a collection of user-defined functions compiled into a
binary format. When you create a library: - Source code is tokenized
(converted to internal format) - Function names get a prefix based on
the filename - The result is saved as a .bb file
Creating a Library
Step 1: Write your library source
Libraries can only contain DEF FN functions. No
variables, constants, or executable code outside functions.
REM MathLib.bas - A simple math library
DEF FN add$(x$, y$)
RETURN x$ + y$
END DEF
DEF FN multiply$(x$, y$)
RETURN x$ * y$
END DEFStep 2: Compile the library
bazzbasic.exe -lib MathLib.bas
Output:
Created library: MathLib.bb
Library name: MATHLIB
Size: {size} bytes
The library name is derived from the filename (uppercase, without extension).
Using a Library
Include the library and call library functions with the
FN keyword using the library prefix:
INCLUDE "MathLib.bb"
[inits]
LET a$ = 5
LET b$ = 3
[main]
PRINT "5 + 3 = "; FN MATHLIB_add$(a$, b$)
PRINT "5 * 3 = "; FN MATHLIB_multiply$(a$, b$)
ENDOutput:
5 + 3 = 8
5 * 3 = 15
Naming Convention
| Source file | Library name | Function prefix |
|---|---|---|
| MathLib.bas | MATHLIB.bb | MATHLIB_ |
| StringUtils.bas | STRINGUTILS.bb | STRINGUTILS_ |
| MyGame.bas | MYGAME.bb | MYGAME_ |
Original function add$() becomes
MATHLIB_add$() when compiled from MathLib.bas.
Accessing Main Program Constants
Libraries cannot define constants, but library functions can access constants defined in the main program:
INCLUDE "Utils.bb"
[inits]
LET APP_NAME# = "MyApp"
LET APP_VERSION# = "1.0"
[main]
PRINT FN UTILS_getAppInfo$() ' Can use APP_NAME# and APP_VERSION#
ENDREM Utils.bas - Library source
DEF FN getAppInfo$()
RETURN APP_NAME# + " v" + APP_VERSION#
END DEFLibrary Rules
- Functions only — Libraries cannot contain variables, constants, or loose code
- Automatic prefix — All functions get the library name as prefix
- No conflicts — Multiple libraries can have functions with the same base name
- Binary format —
.bbfiles are not human-readable - Constant access — Library functions can read constants from the main program
- Not embedded in -exe packages - .bb files always travel alongside the executable
Error Handling
Invalid library content:
bazzbasic.exe -lib BadLib.bas
Library validation failed: Line 5: Libraries can only contain DEF FN functions. Found: TOK_LET
Library not found:
Error: Line 1: Library not found: missing.bb
If the INCLUDE "missing.bb" line is inside an included
.bas file, the message names that file:
Error: helpers.bas line 3: Library not found: missing.bb.
Runtime error inside a library function:
Error in MathLib.bb line 4: Undefined variable: YY$
Since 1.8, the message names the library, and the line number is the
line in the library’s source file - here a typo yy$ on line
4 of MathLib.bas.
Benefits of Libraries
- Faster loading — Pre-tokenized code loads instantly
- No name conflicts — Automatic prefixes prevent collisions
- Code organization — Separate reusable code from main program
- Smaller files — Binary format is typically 30–50% smaller than source for larger files
Note: For small files with only a few functions, the
.basfile may be smaller than the tokenized.bbfile due to metadata overhead. The size advantage shifts to the tokenized format as file size grows.
Distributing Libraries
When distributing your program with libraries:
MyGame/
├── MyGame.exe (or MyGame.bas)
├── MathLib.bb
├── StringLib.bb
└── SDL2.dll
Libraries must be in the same directory as the main program, or in a path relative to it. Packaging your program with -exe (or IDE Compile as Exe) does NOT embed .bb files into the exe - only .bas INCLUDEs are embedded - so every used .bb must accompany the exe, like SDL2.dll and assets.
More Command Line Features
These options are for the interpreter,
bazzbasic.exe.
Overview
| Command | What it does |
|---|---|
bazzbasic.exe |
Opens the IDE (BazzBasic-IDE.exe in the same folder).
If the IDE is not there, shows the usage below. |
bazzbasic.exe file.bas [args...] |
Runs a program. Extra arguments are passed to the program. |
bazzbasic.exe -exe file.bas |
Creates a standalone executable. See Creating EXE. |
bazzbasic.exe -lib file.bas |
Creates a library (.bb). See Creating Libraries. |
bazzbasic.exe -v |
Shows the version. |
bazzbasic.exe -guide |
Shows a link to the Beginner’s Guide. |
bazzbasic.exe -checkupdate |
Checks for a new release. |
Packaged executables (made with -exe, see Creating EXE) receive
arguments the same way: myprog.exe arg1 arg2 gives ARGCOUNT
= 2 and ARGS(0) = “arg1” (0-based, just like
bazzbasic.exe myprog.bas arg1 arg2).
After an error, bazzbasic.exe exits with code 1, so
scripts and .bat files can detect it. A program that ends
normally exits with code 0. Runtime errors are printed as
Error at line N: <message>, where N is the line that
caused the error. An error inside an INCLUDEd file or a .bb
library names that file and the line in it:
Error in helpers.bas line 2: <message> (see Preprocessor).
Get a link to the BazzBasic Beginner’s Guide
bazzbasic.exe -guide
or
bazzbasic.exe -help
Get Version of Your Current BazzBasic
bazzbasic.exe -version
or
bazzbasic.exe -v
Check For New Version Release
bazzbasic.exe -checkupdate
-checkupdates works too. The result is one of:
- a newer version is available, with a download link
- you are running the latest version
- you are running a version newer than the latest release (for example a build made from the source code)
AI assisted learning
BazzBasic is a young language, so AI models have seen very little of it in their training data. Left alone, an AI will happily guess and write BASIC that looks right but uses syntax from QBasic, FreeBASIC or some other dialect.
To fix that, BazzBasic has an official AI SKILL: a skill folder named
bazzbasic-code built around SKILL.md (the core
language) plus topic files in references/ — graphics &
sound, mouse & gamepad, file I/O, JSON & XML, network (including
calling AI/LLM APIs), date & time and the IDE. Together they teach
an AI the language — syntax, variable rules, commands, functions, common
pitfalls and idioms.
BazzBasic
AI SKILL (the bazzbasic-code skill folder) on Hugging
Face
The SKILL was originally written by uploading the BazzBasic documentation to Claude, ChatGPT and Mistral Le Chat and asking them to build a reference that works specifically as an aid for AI. It has been refined against the interpreter source ever since.
What is a SKILL?
A skill is a way to give an AI a piece of expert knowledge it can pick up when it needs it. The format was introduced by Anthropic for Claude in October 2025 as Agent Skills and published as an open standard (agentskills.io) in December 2025. Since then it has been adopted by many AI tools and coding agents.
A skill is simply a folder containing a file named
SKILL.md. The file is plain Markdown with a short header at
the top:
---
name: bazzbasic-code
description: "BazzBasic BASIC interpreter language reference. Use when writing,
debugging, or explaining BazzBasic code (.bas files). ..."
---
# BazzBasic Language Reference
...
- name — a short identifier for the skill.
- description — tells the AI when to use the skill.
- Everything after the header is the actual knowledge.
The clever part is how the AI uses it. At first the AI only reads the name and the description, which costs almost nothing. When you ask something that matches the description — for example “write me a BazzBasic program that draws a starfield” — the AI loads the full SKILL and follows it. When you talk about something else, the SKILL stays out of the way.
A skill folder may also contain extra files, and the BazzBasic SKILL
uses them: the large topics live in references/*.md, which
SKILL.md points to, and README.md carries a
copy-paste setup prompt that lists every file.
How to use it
Tools that support skills (for example Claude, Claude Code and many other coding agents):
- Download the whole
bazzbasic-codefolder —SKILL.md,README.mdand all ofreferences/. - Add the folder to your tool’s skills directory, or upload it as a skill in the tool’s settings.
After that the AI uses the SKILL automatically whenever BazzBasic comes up.
Native SKILL.md support
These popular AI services can all load SKILL.md as a
skill automatically (as of October 2026):
- Anthropic Claude (Claude.ai, Claude Code)
- OpenAI ChatGPT and Codex
- Google Gemini CLI
- Mistral Vibe
- GitHub Copilot (VS Code agent mode, Copilot CLI)
- Microsoft 365 Copilot (Cowork)
- xAI Grok
- OpenCode.AI
- DeepSeek Seek Code
- OpenClaw.AI
- OpenCode.AI
- Tricentis Tabnine
- Kimi.com
- …and many more.
The list grows all the time.
See agentskills.io/clients
for them all.
Every other AI understands it too. The files are
plain Markdown — attach them to the chat or paste them into your project
instructions. README.md contains a ready-made setup prompt
that lists every file: copy-paste it.
License and updates
The SKILL is published under the MIT license. It evolves together with BazzBasic itself, and the version number at the top of the file tells which BazzBasic version it describes. Check for a newer copy from time to time — especially after a new BazzBasic release.
Rosetta Code
Rosetta Code is a programming chrestomathy site — a collection of common programming tasks solved in as many languages as possible. It’s a great way to see how a language thinks and compare it to others you already know.
BazzBasic has its own category on Rosetta Code:
The same examples are also available in the BazzBasic GitHub repository:
And also they comes with each release, inside of Examples subfolder.
BazzBasic Beginner’s Guide
A beginner’s guide to BazzBasic is now available here: BazzBasic_Beginners_Guide.pdf
Markdown version here
This guide covers everything you need to get started: variables, loops, conditions, functions, file handling, JSON, networking, graphics, sound, and more. Each chapter builds on the last, with working example programs throughout.
This is not a complete reference.
It is a starting point.
The full BazzBasic manual covers everything else.
Author: Kristian Virtanen (EkBass)
License: CC BY-ND 4.0
— free to share with attribution, translations permitted, modifications
are not permitted.
Variables & Constants
- Variables store values that can change during program execution.
- Constants store value that can not be changed during execution
Declaration
- Variables and constants must be initialized with
LETbefore they can be used - BazzBasic variables are not typed, but work the same way as in JavaScript, for example.
- A variable needs the suffix $
- A constant needs the suffix #
Variables
' Basic init for variables
LET a$ = "Foo"
PRINT a$ ' Output: "Foo"
LET b$ = 1
PRINT b$ ' Output: 1
LET c$ = 1 + 2
PRINT c$ ' Output: 3Constants
' Basic init for constants
LET GRAVITY# = 9.81
LET MAX_PLAYERS# = 4
LET GAME_TITLE# = "Space Invaders"Built-in constants such as PI# already exist (see Built-in Constants) and cannot be
redefined: LET PI# = 3.14 stops the program with
Cannot redefine constant 'PI#'. Give your own constants
other names.
LET only when init
' Once variable is initialized, you do not need LET anymore
LET a$ = 1
a$ = 3
PRINT a$ ' Output: 3Untyped data type
' Variable stores either a number or a text.
' It is ok to change the type of data.
LET a$ = 1
PRINT a$ ' Output: 1
a$ = "Foo"
PRINT a$ ' Output: FooVersatile usage
' Math with variables and multiple inits in single line
LET a$ = 1, b$ = 2
LET c$ = a$ + b$
LET MY_CONST# = c$ * b$Error situation examples
' Some errors
a$ = 1 ' error: a$ not initialized
LET B# = 1
B# = B# + 3 ' error: Constant B# had value 1 when initialized, not allowed to change anymoreInit with out a value
' If you want just to init var and not give value yet
LET a$ ' declares variable
a$ = 1 ' inits value 1 to variable
LET B# ' works, but is a bit stupid since now B# is constant with value of nothingConcatenated values
LET x$ = 10
x$ += 5 ' 15
x$ -= 3 ' 12
x$ *= 2 ' 24
x$ /= 4 ' 6
PRINT x$ ' 6
LET s$ = "Hello"
s$ += " World"
PRINT s$ ' Hello WorldImportant: Not allowed with constants “#”
Exceptions
FOR and INPUT
When a variable is introduced with a FOR...NEXT or
INPUT command, it does not need to be initialized with
LET:
REM name$ is initialized by INPUT
INPUT "What is your name? ", name$
REM i$ is initialized by FOR
FOR i$ = 1 TO 10
PRINT i$
NEXTComparing variables
A comparison is true if: - two string variables are equal - two number variables are equal - the value of the number in the string variable is the same as the number variable
LET a$, b$, c$
a$ = "12" ' a$ holds the text "12"
b$ = 12 ' b$ holds the number 12
c$ = b$ + a$ ' c$ is now "1212" - + joins when one side is text
' Output of this IF...THEN: Same
IF a$ = b$ THEN
PRINT "Same"
ELSE
PRINT "Different"
ENDIF
' Output of this IF...THEN: Different
IF a$ = c$ THEN
PRINT "Same"
ELSE
PRINT "Different"
ENDIF
c$ = b$ + VAL(a$) ' c$ is now 24 - VAL() turns the text into a number
' Output of this IF...THEN: Same
IF c$ = 24 THEN
PRINT "Same"
ELSE
PRINT "Different"
ENDIF+ with text: if either side of
+ is a string, + joins the values as text
instead of adding them. It works from left to right, and *
and / are calculated first.
PRINT "12" + 3 ' Output: 123
PRINT 1 + "23" ' Output: 123
PRINT 1 + 2 ' Output: 3
PRINT 1 + 2 + "Foo" + 4 * 5 ' Output: 3Foo20Note: Although 123 and “123” produce TRUE in an IF…THEN comparison, it is best to keep numeric variables as numeric and string variables as string.
A comparison between a numeric and string variable is only made if the data type of the variable contents is not the same. This slows down the comparison process if it is done significantly.
Built-in Constants
BazzBasic provides a full range of automatically initialized constants
Math: | Constant | Description | |———-|————-| |
PI#, HPI#, QPI#,
TAU# | π, π/2, π/4 and 2π — see Math Functions | | EULER# | e ≈
2.718281828459045 | | AU# | 149597870700 — astronomical
unit in metres (exact, IAU 2012) |
Note: if older code declares its own
AU#withLET, remove that line — built-in constants cannot be redefined, so it is now an error.
Physics: | Constant | Description | |———-|————-| |
PHI# | 1.618033988749895 — golden ratio φ (since 1.8) | |
GRAV# | 6.6743E-11 — gravitational constant, m^3 kg^-1 s^-2
(since 1.8) | | GRAV_E# | 9.80665 — standard gravity on
Earth, m/s^2 (since 1.8) |
PRINT PHI# ' Output: 1.618033988749895
PRINT GRAV_E# ' Output: 9.80665Colors: | Constant | Value (ARGB) | RGB |
|———-|————–|—–| | BLACK# | 0xFF000000 | (0, 0, 0) | |
WHITE# | 0xFFFFFFFF | (255, 255, 255) | | RED#
| 0xFFFF0000 | (255, 0, 0) | | GREEN# | 0xFF00FF00 | (0,
255, 0) | | BLUE# | 0xFF0000FF | (0, 0, 255) | |
YELLOW# | 0xFFFFFF00 | (255, 255, 0) | | CYAN#
| 0xFF00FFFF | (0, 255, 255) | | MAGENTA# | 0xFFFF00FF |
(255, 0, 255) | | GRAY# | 0xFF808080 | (128, 128, 128) | |
ORANGE# | 0xFFFFA500 | (255, 165, 0) | |
TRANSPARENT# | 0x00000000 | (0, 0, 0, alpha 0) |
Use them as the color parameter of drawing commands
(PSET, LINE, CIRCLE,
PAINT, DRAWSTRING, LOADSHAPE) —
like RGB(r, g, b) values they are 32-bit ARGB.
COLOR (console text colors) still takes a palette index
0–15 only. Since 1.8.
SCREEN 320, 200
LINE (10, 10)-(100, 100), RED#
CIRCLE (160, 100), 40, YELLOW#System: | Constant | Description | |———-|————-| |
PRG_ROOT# | Full path to the program’s base directory
(always ends with a directory separator, so you can concatenate a
relative path directly) | | BBVER# | BazzBasic version
string (e.g. "1.1d") | | BBBUILD# | Build time
of the interpreter, "dd-mm-yyyy hh:mm:ss"
(e.g. "06-11-2026 20:45:57"). A program compiled with
-exe reports the build time of the interpreter it was made
with, not the time it was compiled |
PRINT "Version: "; BBVER# ' Output: 1.1d
PRINT "Build: "; BBBUILD# ' Output: 06-11-2026 20:45:57
PRINT "Root: "; PRG_ROOT# ' Output: C:\path\to\program\Keyboard:
Arrow Keys
KEY_UP# |
KEY_DOWN# |
KEY_LEFT# |
KEY_RIGHT# |
Special Keys
KEY_ESC# |
KEY_TAB# |
KEY_BACKSPACE# |
KEY_ENTER# |
KEY_SPACE# |
KEY_INSERT# |
KEY_DELETE# |
KEY_HOME# |
KEY_END# |
KEY_PGUP# |
KEY_PGDN# |
Modifier Keys
KEY_LSHIFT# |
KEY_RSHIFT# |
KEY_LCTRL# |
KEY_RCTRL# |
KEY_LALT# |
KEY_RALT# |
KEY_LWIN# |
KEY_RWIN# |
Function Keys
KEY_F1# |
KEY_F2# |
KEY_F3# |
KEY_F4# |
KEY_F5# |
KEY_F6# |
KEY_F7# |
KEY_F8# |
KEY_F9# |
KEY_F10# |
KEY_F11# |
KEY_F12# |
Numpad Keys
KEY_NUMPAD0# |
KEY_NUMPAD1# |
KEY_NUMPAD2# |
KEY_NUMPAD3# |
KEY_NUMPAD4# |
KEY_NUMPAD5# |
KEY_NUMPAD6# |
KEY_NUMPAD7# |
KEY_NUMPAD8# |
KEY_NUMPAD9# |
KEY_NUMPAD_PLUS# |
KEY_NUMPAD_MINUS# |
KEY_NUMPAD_MUL# |
KEY_NUMPAD_DIV# |
KEY_NUMPAD_DOT# |
Numpad keys give the same value on every keyboard layout. Numpad
Enter returns the same value as KEY_ENTER#.
Punctuation Keys
KEY_COMMA# |
KEY_DOT# |
KEY_MINUS# |
KEY_EQUALS# |
KEY_SLASH# |
KEY_BACKSLASH# |
KEY_SEP# |
KEY_GRAVE# |
KEY_LBRACKET# |
KEY_RBRACKET# |
Punctuation keys depend on the keyboard layout. A character that needs Shift or AltGr on the user’s keyboard (for example
=and/on a Finnish keyboard) cannot be detected with these constants. See Keyboard layouts.
Alphabet Keys
KEY_A# |
KEY_B# |
KEY_C# |
KEY_D# |
KEY_E# |
KEY_F# |
KEY_G# |
KEY_H# |
KEY_I# |
KEY_J# |
KEY_K# |
KEY_L# |
KEY_M# |
KEY_N# |
KEY_O# |
KEY_P# |
KEY_Q# |
KEY_R# |
KEY_S# |
KEY_T# |
KEY_U# |
KEY_V# |
KEY_W# |
KEY_X# |
KEY_Y# |
KEY_Z# |
Number Keys
KEY_0# |
KEY_1# |
KEY_2# |
KEY_3# |
KEY_4# |
KEY_5# |
KEY_6# |
KEY_7# |
KEY_8# |
KEY_9# |
Gamepad: (see Gamepad)
Gamepad Buttons
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# |
Gamepad Axes
PAD_LX# |
PAD_LY# |
PAD_RX# |
PAD_RY# |
PAD_LT# |
PAD_RT# |
Naming Rules
- Must end with
$(variable) or#(constant) - Can contain letters, numbers, and underscores
- Cannot start with a number
- Case-insensitive
Valid names:
LET score$
LET player1_name$
LET MAX_VALUE#
LET x$Invalid names:
LET score ' Missing suffix
LET 1player$ ' Starts with numberErrors
In case of error, BazzBasic stops with proper error message.
LET a$ = 100 ' ok
b$ = 200 ' Error at line 2: Undefined variable: B$ (use LET for first assignment)Scope
Variables initialized within the main code belong to the same scope.
IF 1 = 1 THEN
LET x$ = 10
END IF
PRINT x$ ' Output: 10 (x$ is still accessible)- Variables initialized and modified in user-defined functions do not belong to the same scope.
- However, global constants are available.
- Arrays follow the same scoping as variables - they are not global.
To pass an array into a DEF FN function, pass it as a JSON string with
ASJSON()and rebuild it inside withASARRAY()(see User-defined Functions).
LET a$ = 1 ' Global variable
LET b$ = 100 ' Global variable
LET C# = "Foo" ' Global constant
DEF FN test$(a$) ' Local parameter a$ is initialized here
LET b$ = 2 ' Local b$ (separate from global b$)
PRINT b$ ' Output: 2
PRINT C# ' Output: Foo
a$ = a$ * b$ ' Uses local a$ (100) and local b$ (2)
RETURN a$ ' Returns 200
END DEF
PRINT FN test$(b$) ' Output: 200
PRINT a$ ' Output: 1
PRINT b$ ' Output: 100Arrays & JSON
Arrays store collections of values. BazzBasic arrays are fully dynamic and support numeric, string, or mixed indexing.
- Arrays store values that can change during program execution.
- All array names must end with
$.
Initialization
- Arrays must be initialized with
DIMbefore they can be used - Like variables or constants, arrays are not strongly typed
- An array needs the suffix ‘$’.
DIM MAX#stops the program:Error at line 1: DIM: expected an array name ending in $, got 'MAX#'. - Re-declaring an existing array in the main program with
DIMdoes not clear it; useDELARRAYto remove it. (Inside a function,DIMalways creates a fresh, empty local array.) - Arrays have no fixed size.
DIM scores$(10)is accepted, but the(10)is ignored: you get the same empty array as withDIM scores$. Nothing inside the parentheses is read, soDIM scores$(n$)declares onlyscores$. DIM x$ = 5declares the arrayx$and stores 5 inx$(0). For a plain variable, useLET x$ = 5. (A text ofkey=valuelines fills named keys instead, see Loading key=value Files into Arrays below.) A name takes a size or a value, not both:DIM a$(10) = 5is an error.
DIM scores$
DIM names$
DIM matrix$Multiple declarations:
DIM a$, b$, c$DIM ends at the end of the line or at :, so
other statements can follow on the same line:
DIM a$, b$ : a$(0) = 1 : b$(0) = 2
PRINT a$(0) + b$(0) ' Output: 3Numeric Indexing
Use numbers as indices (0-based):
DIM scores$
scores$(0) = 95
scores$(1) = 87
scores$(2) = 92
PRINT scores$(0) ' Output: 95String Indexing (Associative Arrays)
Use strings as keys:
DIM player$
player$("name") = "Alice"
player$("score") = 1500
player$("level") = 3
PRINT player$("name") ' Output: AliceString keys are case-sensitive: "name",
"Name" and "NAME" are three different keys.
The array name itself is not case-sensitive, so player$,
PLAYER$ and Player$ all refer to the same
array.
DIM word$
word$("apple") = 1
word$("Apple") = 2
PRINT LEN(word$()) ' Output: 2
PRINT word$("apple") ' Output: 1If you want keys that ignore case, normalize them yourself with
UCASE() or LCASE():
DIM count$
LET key$ = "Apple"
count$(LCASE(key$)) = 1
PRINT count$("apple") ' Output: 1Multi-dimensional Arrays
Use multiple indices separated by commas:
DIM matrix$
matrix$(0, 0) = "A1"
matrix$(0, 1) = "A2"
matrix$(1, 0) = "B1"
matrix$(1, 1) = "B2"
PRINT matrix$(1, 0) ' Output: B1Mixed Indexing
Combine numeric and string indices:
DIM data$
data$(1, "header") = "Name"
data$(1, "value") = "Alice"
data$(2, "header") = "Age"
data$(2, "value") = 30
PRINT data$(1, "value") ' Output: AliceArray Functions
DELARRAY
Removes the entire array and all its elements:
DIM arr$
arr$("name") = "Test"
arr$(0) = "Zero"
PRINT LEN(arr$()) ' Output: 2
DELARRAY arr$
' Array no longer exists, can be re-declared
DIM arr$
PRINT LEN(arr$()) ' Output: 0DELKEY
Removes an element from the array:
DIM cache$
cache$("temp") = "value"
PRINT HASKEY(cache$("temp")) ' Output: 1
DELKEY cache$("temp")
PRINT HASKEY(cache$("temp")) ' Output: 0DELKEY takes several indexes, just like reading an
element. If the key does not exist, DELKEY does
nothing:
DIM users$
users$(1, "name") = "Bob"
users$(1, "email") = "bob@example.com"
DELKEY users$(1, "email")
PRINT HASKEY(users$(1, "email")) ' Output: 0
PRINT HASKEY(users$(1, "name")) ' Output: 1
DELKEY users$(5, "email") ' No such key - nothing happens
PRINT LEN(users$()) ' Output: 1Since 1.8, DELKEY without a key,
e.g. DELKEY users$(), stops the program with
Error at line N: DELKEY needs a key, e.g. DELKEY arr$(key).
The empty text key is still fine: DELKEY users$("") removes
the element stored under "".
Since 1.8, DELKEY on an array that does not exist (never
declared, a typo in the name, or removed with DELARRAY)
stops the program, just like reading an element of it:
DIM users$
users$("ann") = "Ann"
DELKEY usres$("ann") ' Typo in the array name
' Error at line 4: Array not declared, use DIM first: USRES$Inside DEF FN, an array of the main program is not
visible, so DELKEY on it stops with the “Global array … is
not visible inside DEF FN” message.
HASKEY
Returns 1 if the key exists, 0 otherwise:
DIM config$
config$("debug") = 1
IF HASKEY(config$("debug")) THEN
PRINT "Debug mode is set"
END IF
IF HASKEY(config$("verbose")) = 0 THEN
PRINT "Verbose not set"
END IFSince 1.8, HASKEY also takes several indexes, just like
reading an element. HASKEY(users$(1, "email")) tests the
same element as users$(1, "email") and
users$("1,email"):
DIM users$
users$(0, "name") = "Ann"
users$(1, "name") = "Bob"
users$(1, "email") = "bob@example.com"
PRINT HASKEY(users$(1, "email")) ' Output: 1
PRINT HASKEY(users$(0, "email")) ' Output: 0
PRINT HASKEY(users$("1,email")) ' Output: 1 - same elementBefore 1.8, HASKEY takes only one index - use the joined
key instead: HASKEY(users$(i$ + ",email")).
JOIN
Merges two source arrays into a destination array. If both arrays
share the same key, src2$ overwrites
src1$.
DIM a$
DIM b$
DIM c$
a$("name") = "Alice"
a$("score") = 100
b$("score") = 999 ' Same key as a$ — this wins
b$("level") = 5
JOIN c$, a$, b$
PRINT c$("name") ' Output: Alice (from a$)
PRINT c$("score") ' Output: 999 (b$ overwrote a$)
PRINT c$("level") ' Output: 5 (from b$)LEN and ROWCOUNT
| Function | Meaning |
|---|---|
LEN(arr$()) |
Total element count across all dimensions (note empty parens) |
ROWCOUNT(arr$()) |
Count of first-dimension keys only — use for FOR loops over multi-dim arrays |
DIM sounds$
sounds$("guns", "shotgun_shoot") = "shoot_shotgun.wav"
sounds$("guns", "shotgun_reload") = "reload_shotgun.wav"
sounds$("guns", "ak47_shoot") = "shoot_ak47.wav"
sounds$("guns", "ak47_reload") = "reload_ak47.wav"
sounds$("food", "ham_eat") = "eat_ham.wav"
PRINT LEN(sounds$()) ' 5 - total elements across both "guns" and "food" groups
PRINT ROWCOUNT(sounds$()) ' 2, "guns" & "food"ARRKEY
Returns the key at a given 0-based index, in insertion order. Pairs
with LEN(arr$()) to loop over associative (string-keyed)
arrays using ordinary FOR/NEXT or WHILE/WEND —
BazzBasic has no dedicated FOREACH.
DIM car$
car$("manufacturer") = "Ford"
car$("engine") = "1.6 Eco"
car$("color") = "Blue"
FOR i$ = 0 TO LEN(car$()) - 1
LET key$ = ARRKEY(car$(), i$)
PRINT key$; " = "; car$(key$)
NEXT i$
' Output:
' manufacturer = Ford
' engine = 1.6 Eco
' color = BlueAlso works with WHILE/WEND:
LET i$ = 0
WHILE i$ < LEN(car$())
LET key$ = ARRKEY(car$(), i$)
PRINT key$; " = "; car$(key$)
i$ = i$ + 1
WENDNumeric-keyed arrays work the same way — ARRKEY returns
the key as a string regardless of whether the array uses numbers or
names as keys. An out-of-range index produces an error rather than an
empty string, so a typo in the loop bound won’t fail silently:
PRINT ARRKEY(car$(), 99)
' Error at line N: ARRKEY: index 99 out of range for array CAR$Practical Examples
Pass values to user-defined functions
Arrays cannot be passed directly to functions. Instead, pass individual elements as values or whole array as JSON string.
As single values
DIM a$
a$("name") = "Foo"
a$("age") = 19
a$(1) = 1
DEF FN func$(a$, b$, c$)
PRINT a$
PRINT b$
PRINT c$
RETURN 0
END DEF
LET b$ = FN func$(a$("name"), a$("age"), a$(1))
' Output:
' Foo
' 19
' 1As JSON
The entire JSON dataset is processed as one large string, so it can be passed as a single parameter to a function.
' ==================================================
' Example how to pass array to user-defined function
' Starting from ver. 1.2
' EkBass, public domain
' ==================================================
' User-defined functions
DEF FN ArrayAsParam$(data$)
DIM array$
LET count$= ASARRAY(array$, data$)
LET daString$
daString$ = array$("name") + "\n"
daString$ = daString$ + array$("score") + "\n"
daString$ = daString$ + array$("address,city") + "\n"
daString$ = daString$ + array$("skills,0") + "\n"
daString$ = daString$ + array$("skills,1") + "\n"
RETURN daString$
END DEF
[inits]
DIM player$
player$("name") = "Alice"
player$("score") = 9999
player$("address,city") = "New York"
player$("skills,0") = "JavaScript"
player$("skills,1") = "Python"
LET json$
[main]
json$ = ASJSON(player$)
' json$ now: "{\"name\":\"Alice\",\"score\":9999,\"address\":{\"city\":\"New York\"},\"skills\":[\"JavaScript\",\"Python\"]}"
[output]
PRINT FN ArrayAsParam$(json$)
END
' Output:
' Alice
' 9999
' New York
' JavaScript
' PythonSimple List
DIM fruits$
LET count$ = 0
fruits$(count$) = "Apple"
count$ = count$ + 1
fruits$(count$) = "Banana"
count$ = count$ + 1
fruits$(count$) = "Cherry"
FOR i$ = 0 TO count$
PRINT fruits$(i$)
NEXTDictionary / Map
DIM translations$
translations$("hello") = "hei"
translations$("goodbye") = "nakemiin"
translations$("thanks") = "kiitos"
' using INPUT auto-initialization here for word$'
INPUT "English word: ", word$
IF HASKEY(translations$(word$)) THEN
PRINT "Finnish: "; translations$(word$)
ELSE
PRINT "Translation not found"
END IFIterating an Associative Array
Combine LEN and ARRKEY to walk every
key/value pair:
DIM scores$
scores$("Alice") = 95
scores$("Bob") = 87
scores$("Carol") = 92
FOR i$ = 0 TO LEN(scores$()) - 1
LET name$ = ARRKEY(scores$(), i$)
PRINT name$; ": "; scores$(name$)
NEXT i$Output:
Alice: 95
Bob: 87
Carol: 92
2D Grid
DIM grid$
' Initialize 3x3 grid
FOR row$ = 0 TO 2
FOR col$ = 0 TO 2
grid$(row$, col$) = "."
NEXT
NEXT
' Place some markers
grid$(0, 0) = "X"
grid$(1, 1) = "O"
grid$(2, 2) = "X"
' Print grid
FOR row$ = 0 TO 2
FOR col$ = 0 TO 2
PRINT grid$(row$, col$); " ";
NEXT
PRINT ""
NEXTOutput:
X . .
. O .
. . X
Error Handling
Array Not Declared
scores$(0) = 95
' Error at line 1: Array not declared, use DIM first: SCORES$Reading an element or DELKEY on an undeclared array
gives the same error.
Element Not Initialized
DIM data$
PRINT data$(0)
' Error at line 2: Array element DATA$(0) not initializedArray Used Without an Index
DIM nums$
nums$(0) = 7
PRINT nums$
' Error at line 3: NUMS$ is an array - use an element like NUMS$(0), or the whole array as a JSON string with ASJSON(NUMS$)Assignment Without a Key
DIM data$
data$() = 5
' Error at line 2: Array assignment needs a key, e.g. arr$(key) = valueSince 1.8 (before, the value was silently stored under the key
""). Give the element a key,
e.g. data$(0) = 5. The empty text key
data$("") = 5 is fine, and LEN(data$()) still
gives the element count.
Element Alone Is Not a Statement
DIM data$
data$(0) = 5
data$(1)
' Error at line 3: Array element alone is not a statement - did you forget '= value'?Since 1.8 (before, it silently did nothing). Only a line with just
the element and no = is an error - reading is not affected:
arr$() in an expression still gives the element count,
e.g. PRINT LEN(data$()). If the name is a
DEF FN function, Foo$(1) without the
FN keyword still gets its own, more specific message
first.
Error messages show array names in uppercase.
Always check with HASKEY or initialize elements before
reading.
Arrays and JSON
BazzBasic arrays map naturally to JSON. Nested JSON objects and arrays become multi-dimensional keys using comma-separated indices.
ASJSON
Converts a BazzBasic array to a JSON string:
DIM player$
player$("name") = "Alice"
player$("score") = 9999
player$("address,city") = "New York"
player$("skills,0") = "JavaScript"
player$("skills,1") = "Python"
LET json$ = ASJSON(player$)
PRINT json$
' Output: {"name":"Alice","score":9999,"address":{"city":"New York"},"skills":["JavaScript","Python"]}Numeric keys decide the shape, at every nesting level: a level
becomes a JSON array only when every key at that level
is a plain non-negative number ("0", "1",
"2", … — no sign, no leading zeros, no spaces)
and the largest index is at most 1,000,000 or the level
is dense (largest index below 4 * key count + 64).
Otherwise the level becomes a JSON object with the
original keys as property names.
DIM a$
a$(0) = "x"
a$(5) = "y"
PRINT ASJSON(a$) ' Output: ["x",null,null,null,null,"y"]
DIM b$
b$("2147483647") = 1
PRINT ASJSON(b$) ' Output: {"2147483647":1}
DIM c$
c$("-5") = 1
c$("007") = 2
PRINT ASJSON(c$) ' Output: {"-5":1,"007":2}Dense arrays (for example SPLIT results or a
FOR i$ = 0 TO n loop filling arr$(i$)) and
small sparse arrays like a$ above stay JSON arrays, so
their output is unchanged from older versions. Keys like
"-5", "007" or " 5" are kept as
object properties instead of being dropped, and a huge key such as
"2147483647" returns instantly instead of freezing the
program (before version 1.7).
JSON object keys keep the array key’s case verbatim — case-sensitive,
same as array string keys (see String Indexing above).
ASARRAY/LOADJSON read property names verbatim
too, so a JSON round-trip preserves case in both directions.
DIM a$
a$("key") = "lower"
a$("KEY") = "upper"
PRINT ASJSON(a$) ' Output: {"key":"lower","KEY":"upper"}Before version 1.7, keys differing only by case collapsed in
ASJSON/SAVEJSON output and one value was
silently lost ({"key":{"":"upper"}}).
ASJSON writes the characters "
< > & ' as
\u0022 \u003C \u003E
\u0026 \u0027. This is valid JSON and reads
back as the same text. An empty array gives {}.
DIM t$
t$("text") = "Tom & Jerry"
PRINT ASJSON(t$) ' Output: {"text":"Tom \u0026 Jerry"}
DIM back$
LET count$ = ASARRAY(back$, ASJSON(t$))
PRINT back$("text") ' Output: Tom & Jerry
DIM e$
PRINT ASJSON(e$) ' Output: {}ASARRAY
Converts a JSON string into a BazzBasic array. Returns the number of values stored by this call (not the size of the array):
DIM data$
LET count$ = ASARRAY(data$, "{\"name\":\"Bob\",\"score\":42}")
PRINT data$("name") ' Output: Bob
PRINT data$("score") ' Output: 42
PRINT count$ ' Output: 2Nested JSON becomes comma-separated keys:
[inits]
DIM data$
LET json$ = "{\"player\":{\"name\":\"Alice\",\"hp\":100},\"skills\":[\"fire\",\"ice\"]}"
[main]
LET count$ = ASARRAY(data$, json$)
PRINT data$("player,name") ' Alice
PRINT data$("player,hp") ' 100
PRINT data$("skills,0") ' fire
PRINT data$("skills,1") ' ice
PRINT count$ ' number of elements
ENDBoth output shapes read back to the same keys: a JSON array becomes
keys "0" to "n-1", a JSON object keeps its
property names as they are. JSON null holes are skipped —
they stay uninitialized and are not counted.
DIM a$
a$(0) = "x"
a$(5) = "y"
DIM b$
LET count$ = ASARRAY(b$, ASJSON(a$))
PRINT count$ ' Output: 2 (the null holes are skipped)
PRINT b$(0) + b$(5) ' Output: xy
DIM h$
h$("2147483647") = 1
DIM g$
LET n$ = ASARRAY(g$, ASJSON(h$))
PRINT n$ ' Output: 1
PRINT g$("2147483647") ' Output: 1ASARRAY reads JSON property names verbatim — case
preserved — so a round-trip ASARRAY(b$, ASJSON(a$)) keeps
keys like "key" and "KEY" distinct.
JSON true and false become 1
and 0, and ASJSON writes them back as numbers.
A number like 1e3 becomes 1000. A
null object member is skipped (the key does not exist); a
null in a list leaves a gap, as shown above.
DIM d$
LET count$ = ASARRAY(d$, "{\"on\":true,\"off\":false,\"big\":1e3,\"gone\":null}")
PRINT d$("on") ' Output: 1
PRINT d$("off") ' Output: 0
PRINT d$("big") ' Output: 1000
PRINT HASKEY(d$("gone")) ' Output: 0
PRINT ASJSON(d$) ' Output: {"on":1,"off":0,"big":1000}ASARRAY adds to the array, it does not clear it.
Values from the JSON replace old values with the same key; all other old
keys stay. A shorter list does not remove old items either:
["x"] over ["a","b","c"] gives x,
b, c. This differs from SPLIT,
which clears the array first. To start clean, remove the array with
DELARRAY and declare it again (DIM alone does
not clear it):
DIM d$
d$("name") = "Old"
d$("extra") = "kept"
LET count$ = ASARRAY(d$, "{\"name\":\"Bob\",\"score\":42}")
PRINT count$ ' Output: 2 (values stored by this call)
PRINT LEN(d$()) ' Output: 3
PRINT d$("name") ' Output: Bob
PRINT d$("extra") ' Output: kept
' Start clean
DELARRAY d$
DIM d$
LET count$ = ASARRAY(d$, "{\"level\":3}")
PRINT LEN(d$()) ' Output: 1LOADJSON, LOADXML and ASARRAY
with XML add to the array the same way.
LOADJSON
Loads a JSON file directly into an array:
DIM scores$
LOADJSON scores$, "highscores.json"
PRINT scores$("first,name") ' Output: depends on file contentsLOADJSON reads both shapes like ASARRAY
does (arrays become keys "0" to "n-1", objects
keep their property names with their case, null values are
skipped).
A missing file stops the program:
Error at line 2: LOADJSON failed: Could not find file '...\highscores.json'.
Check with FILEEXISTS first:
DIM scores$
IF FILEEXISTS("highscores.json") THEN
LOADJSON scores$, "highscores.json"
ELSE
PRINT "No saved scores yet"
END IFSAVEJSON
Saves an array as a formatted JSON file:
DIM save$
save$("level") = 3
save$("hp") = 80
save$("position,x") = 100
save$("position,y") = 200
SAVEJSON save$, "savegame.json"The resulting savegame.json:
{
"level": 3,
"hp": 80,
"position": {
"x": 100,
"y": 200
}
}SAVEJSON writes the same shape ASJSON
produces (both share the same code), formatted as shown above; JSON
object keys keep their case. The file has Windows line ends (CRLF) and
no line end after the last }.
Practical example: HTTP API + JSON
DIM response$
LET raw$ = HTTPGET("https://api.example.com/user/1")
LET count$ = ASARRAY(response$, raw$)
PRINT "Name: "; response$("name")
PRINT "Email: "; response$("email")XML (light model)
BazzBasic can also read and write XML, mainly so that an RSS or Atom feed reader is easy to make. JSON is still the recommended format. XML is heavier, does not map to arrays as cleanly, and its keys are longer. Use XML when the data only comes as XML.
XML is not HTML. A web page does not parse as XML and gives an error.
ASARRAY recognizes the format by itself from the first
character: { or [ means JSON,
< means XML. Nothing else needs to change.
LET xml$ = HTTPGET("https://www.example.com/rss.xml")
IF HTTPERROR <> "" THEN
PRINT "Feed is down: "; HTTPERROR
END
END IF
DIM feed$
LET count$ = ASARRAY(feed$, xml$)
PRINT feed$("rss,channel,0,title,0")
LET i$ = 0
WHILE HASKEY(feed$("rss,channel,0,item," + i$ + ",title,0"))
PRINT "- "; feed$("rss,channel,0,item," + i$ + ",title,0")
i$ += 1
WEND
ENDHow XML becomes keys
Every element below the root gets an index — even when there is only one. The keys are longer than in JSON, but the same loop works for a feed with one item and a feed with a hundred.
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>My feed</title>
<item>
<title>First post</title>
<guid isPermaLink="false">id-1</guid>
<category>News</category>
<category>Weather</category>
<dc:creator>Krisu</dc:creator>
</item>
</channel>
</rss>| Key | Value |
|---|---|
rss,@version |
2.0 |
rss,@xmlns:dc |
http://purl.org/dc/elements/1.1/ |
rss,channel,0,title,0 |
My feed |
rss,channel,0,item,0,title,0 |
First post |
rss,channel,0,item,0,guid,0,@isPermaLink |
false |
rss,channel,0,item,0,guid,0,#text |
id-1 |
rss,channel,0,item,0,category,0 |
News |
rss,channel,0,item,0,category,1 |
Weather |
rss,channel,0,item,0,dc:creator,0 |
Krisu |
- Attributes get
@in front of their name. - Text of an element that also has attributes or
child elements is in
#text. - Prefixes such as
dc:are kept as written in the file. Theirxmlns:declarations are attributes too, soASXMLcan write them back. - CDATA is read as plain text.
- All values are strings — XML has no number type.
Use
VAL()when you need a number. - Comments and the
<!DOCTYPE ...>line are ignored.
Not supported: text and elements mixed together
(<p>Hello <b>world</b>!</p>) keeps
the text and the elements, but not their order. Feeds rarely need this.
Text is also trimmed at both ends, so
<p>Hello <b>world</b></p> gives
p,#text = Hello (the space is gone).
ASXML
Converts a BazzBasic array to an XML string. If the array has a
single top-level key, it becomes the root element; otherwise the root is
<root>:
DIM player$
player$("player,@id") = 7
player$("player,name") = "Alice"
player$("player,score") = 9999
PRINT ASXML(player$)
' Output: <player id="7"><name>Alice</name><score>9999</score></player>Keys must be valid XML names: player$("high score")
gives an error in ASXML, because an XML element name cannot
contain a space.
Numeric keys have no element names, so each value becomes an
<item> inside <root>:
DIM a$
a$(0) = "a"
a$(1) = "b"
PRINT ASXML(a$)
' Output: <root><item>a</item><item>b</item></root>LOADXML
Loads an XML file directly into an array:
DIM cfg$
LOADXML cfg$, "settings.xml"
PRINT cfg$("config,player,0")Like LOADJSON, a missing file stops the program
(LOADXML failed: Could not find file ...), so check with
FILEEXISTS first.
SAVEXML
Saves an array as a formatted XML file:
DIM cfg$
cfg$("config,player,0") = "Krisu"
cfg$("config,volume,0") = 80
cfg$("config,setting,0,@name") = "fullscreen"
cfg$("config,setting,0,#text") = "on"
SAVEXML cfg$, "settings.xml"The resulting settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<player>Krisu</player>
<volume>80</volume>
<setting name="fullscreen">on</setting>
</config>The file has LF line ends and a line end after the last tag.
HTTP Headers with Arrays
HTTPGET and HTTPPOST accept an optional headers$ array
as the last parameter. This enables authenticated API calls, custom
content types, and any other HTTP header needs.
DIM headers$
headers$("Authorization") = "Bearer mytoken123"
headers$("Content-Type") = "application/json"
LET raw$ = HTTPGET("https://api.example.com/data", headers$)DIM headers$
headers$("Authorization") = "Bearer mytoken123"
headers$("Content-Type") = "application/json"
DIM body$
body$("model") = "gpt-4.1-mini"
body$("messages,0,role") = "user"
body$("messages,0,content") = "Hello"
body$("max_tokens") = 100
LET raw$ = HTTPPOST("https://api.openai.com/v1/chat/completions", ASJSON(body$), headers$)
DIM result$
LET count$ = ASARRAY(result$, raw$)
PRINT result$("choices,0,message,content")Loading key=value Files into Arrays
FILEREAD can populate an array directly from a
key=value formatted text file. If the target variable is a
DIM’d array, BazzBasic automatically parses the file
contents line by line into array elements.
DIM config$ = FILEREAD("settings.txt")
PRINT config$("width") ' Output: 800
PRINT config$("height") ' Output: 600Where settings.txt contains:
width=800
height=600
# Comment, ignored, only when reading to array!
title=My Game
.env files
This makes .env files work naturally for storing API
keys and configuration outside of source code:
IF FILEEXISTS(".env") = 0 THEN
PRINT "Error: .env file not found"
END
END IF
DIM env$ = FILEREAD(".env")
PRINT env$("OPENAI_API_KEY")Where .env contains:
OPENAI_API_KEY=sk-proj-...
# Comment
ANTHROPIC_API_KEY=sk-ant-...
# Important! In-line comments not yet supported
Important: Add .env to your
.gitignore to keep API keys out of version control.
Operators
Logical Values
TRUE, FALSE
Boolean constants.
LET gameOver$ = FALSE
WHILE NOT gameOver$
' game loop
IF lives$ = 0 THEN gameOver$ = TRUE
WENDArithmetic Operators
| Operator | Description | Example |
|---|---|---|
+ |
Addition | 5 + 3 → 8 |
- |
Subtraction | 5 - 3 → 2 |
* |
Multiplication | 5 * 3 → 15 |
/ |
Division | 10 / 3 → 3.333... |
% |
Modulo (remainder) | 10 % 3 → 1 |
Division by zero does not stop the program, it gives
0. This is the same for /, /=,
% and MOD:
LET a$ = 10
a$ /= 0
PRINT 10 / 0 ' Output: 0
PRINT a$ ' Output: 0
PRINT 10 % 0 ' Output: 0
PRINT MOD(10, 0) ' Output: 0Check the divisor first if that matters.
BazzBasic has no \ (integer division) or ^
(power) operator. Use INT(a / b) and
POW(a, b):
PRINT INT(10 / 3) ' Output: 3
PRINT POW(2, 8) ' Output: 256Writing 10 \ 3 or 2 ^ 8 stops the program
before it starts, with a hint:
Error: Line 1: Unexpected character '\' - BazzBasic has no integer division operator, use INT(a / b).
Any other character that is not part of the language (outside strings,
comments and labels), such as @, is an error too.
Comparison Operators
| Operator | Description | Example |
|---|---|---|
= |
Equal to | x = 5 |
<> |
Not equal to | x <> 5 |
< |
Less than | x < 10 |
> |
Greater than | x > 0 |
<= |
Less than or equal | x <= 100 |
>= |
Greater than or equal | x >= 1 |
Comparing text
Comparisons between two strings ignore case:
"abc" = "ABC" is 1 (true), and
"a" < "B" is 1 too.
To compare exactly, for example a password, a key or an ID, use
SAME(a$, b$). It returns 1 only if both texts
are identical, case included:
LET password$ = "Open Sesame"
LET guess$ = "open sesame"
IF guess$ = password$ THEN PRINT "= says: match"
IF SAME(guess$, password$) THEN
PRINT "SAME: match"
ELSE
PRINT "SAME: no match"
END IF
' Output:
' = says: match
' SAME: no matchSAME compares text. For numbers use =.
Before version 1.7 there is no SAME.
Check the length and use INSTR, which is
case-sensitive:
LET password$ = "Open Sesame"
LET guess$ = "open sesame"
IF LEN(guess$) = LEN(password$) AND INSTR(guess$ + "~", password$ + "~") = 1 THEN
PRINT "Exact: match"
ELSE
PRINT "Exact: no match"
END IF
' Output:
' Exact: no matchThe + "~" is needed so that two empty strings count as
equal (INSTR("", "") gives 0). Any character
works, as long as both sides get the same one.
Logical Operators
| Operator | Description | Example |
|---|---|---|
AND |
Logical AND | x > 0 AND x < 10 |
OR |
Logical OR | x < 0 OR x > 100 |
NOT |
Logical NOT | NOT finished |
String Operators
| Operator | Description | Example |
|---|---|---|
+ |
Concatenation | "Hello" + " " + "World" →
"Hello World" |
If either side of + is a string, + joins
instead of adding, from left to right: "12" + 3 →
123, 1 + 2 + "Foo" → 3Foo. See Comparing variables.
Operator Precedence
From highest to lowest:
()- ParenthesesNOT- Logical NOT*,/,%- Multiplication, Division, Modulo+,-- Addition, Subtraction=,<>,<,>,<=,>=- ComparisonAND- Logical ANDOR- Logical OR
Comments
BazzBasic supports two comment styles.
REM
Traditional BASIC keyword comment.
REM This is a comment
REM Initialize player position
LET x$ = 100Single Quote
Shorter alternative, works inline too.
' This is a comment
LET x$ = 100 ' Inline commentBoth styles are completely identical in behavior — use whichever you
prefer. Single quote ' is generally preferred for its
brevity.
' ============================================
' player.bas - Player movement logic
' BazzBasic: https://github.com/EkBass/BazzBasic
' ============================================
[inits]
LET x$ = 320 ' Start at center X
LET y$ = 240 ' Start at center YUser Defined Functions
Basic Syntax
Note: Name of user-defined function must have ‘$’ as suffix
DEF FN functionName$(param1$, param2$, ...)
' Function body
RETURN value
END DEFParameters must end with $ too. A # name is
a constant and cannot be a parameter:
DEF FN area$(w$, H#) ' Error at line 1: DEF FN AREA$: expected a parameter name ending in $, got 'H#' - # names are constants and cannot be parameters
RETURN w$ * H#
END DEFImportant to remember
A user-defined function must always return a value, and BazzBasic
always expects that value to be used — assigned to a variable or passed
to a command like PRINT.
DEF FN double$(x$)
RETURN x$ * 2
END DEF
PRINT FN double$(21) ' ✓ OK - return value goes to PRINT
LET foo$ = FN double$(5) ' ✓ OK - return value stored in foo$
FN double$(21) ' ✗ ERROR - return value has nowhere to goSimple Function
DEF FN double$(x$)
RETURN x$ * 2
END DEF
PRINT FN double$(21) ' Output: 42
PRINT FN double$(5) ' Output: 10Multiple Parameters
DEF FN add$(a$, b$)
RETURN a$ + b$
END DEF
DEF FN multiply$(a$, b$)
RETURN a$ * b$
END DEF
PRINT FN add$(3, 4) ' Output: 7
PRINT FN multiply$(3, 4) ' Output: 12A call must pass exactly as many arguments as the function has
parameters. FN add$(3) stops with
Error at line N: FN ADD$: expected 2 arguments, got 1. This
applies to functions from .bb libraries too.
Array data as parameter
Arrays cannot be passed directly to functions. Instead, pass individual elements as values or whole array as JSON string.
As single values
DIM a$
a$("name") = "Foo"
a$("age") = 19
a$(1) = 1
DEF FN func$(a$, b$, c$)
PRINT a$
PRINT b$
PRINT c$
RETURN 0
END DEF
LET b$ = FN func$(a$("name"), a$("age"), a$(1))
' Output:
' Foo
' 19
' 1As JSON
' ==================================================
' Example how to pass array to user-defined function
' Starting from ver. 1.2
' EkBass, public domain
' ==================================================
' User-defined functions
DEF FN ArrayAsParam$(data$)
DIM array$
LET count$= ASARRAY(array$, data$)
LET daString$
daString$ = array$("name") + "\n"
daString$ = daString$ + array$("score") + "\n"
daString$ = daString$ + array$("address,city") + "\n"
daString$ = daString$ + array$("skills,0") + "\n"
daString$ = daString$ + array$("skills,1") + "\n"
RETURN daString$
END DEF
[inits]
DIM player$
player$("name") = "Alice"
player$("score") = 9999
player$("address,city") = "New York"
player$("skills,0") = "JavaScript"
player$("skills,1") = "Python"
LET json$
[main]
json$ = ASJSON(player$)
' json$ now: {"name":"Alice","score":9999,"address":{"city":"New York"},"skills":["JavaScript","Python"]}
[output]
PRINT FN ArrayAsParam$(json$)
END
' Output:
' Alice
' 9999
' New York
' JavaScript
' PythonString Functions
DEF FN greet$(name$)
RETURN "Hello, " + name$ + "!"
END DEF
PRINT FN greet$("Alice") ' Output: Hello, Alice!Functions with Logic
DEF FN max$(a$, b$)
IF a$ > b$ THEN
RETURN a$
ELSE
RETURN b$
END IF
END DEF
DEF FN min$(a$, b$)
IF a$ < b$ THEN
RETURN a$
ELSE
RETURN b$
END IF
END DEF
PRINT FN max$(10, 25) ' Output: 25
PRINT FN min$(10, 25) ' Output: 10Recursive Functions
Functions can call themselves:
DEF FN factorial$(n$)
IF n$ <= 1 THEN
RETURN 1
END IF
RETURN n$ * FN factorial$(n$ - 1)
END DEF
PRINT FN factorial$(5) ' Output: 120
PRINT FN factorial$(10) ' Output: 3628800Scope
User-defined functions have their own local scope that is completely isolated from the main program:
- Function parameters are local to the function
- Variables declared with
LETinside a function are local to that function
- Functions cannot access or modify global variables from the main program
- The same goes for arrays: global arrays are not
visible inside a function. Pass an array as a JSON string with
ASJSON()and rebuild it inside withASARRAY() - An array declared with
DIMinside a function is local and starts empty on every call (and on every recursion level) - Parameters are passed by value - changes to parameters don’t affect the original variables
LET b$ = 100 ' Global variable
LET C# = "Foo" ' Global constant
DEF FN test$(a$) ' Parameter a$ is local
LET b$ = 2 ' Local b$ (separate from global b$)
PRINT C# ' Global constants are available
a$ = a$ * b$ ' Uses local a$ (100) and local b$ (2)
RETURN a$ ' Returns 200
END DEFIn this example: - The global b$ has
value 100 - When calling FN test$(b$), the
value 100 is passed to parameter a$ -
Inside the function, a new local variable
b$ is created with value 2 - The local b$ is
completely separate from the global b$ - The function
calculates a$ * b$ = 100 × 2 = 200 - The global
b$ remains unchanged at 100
Labels Inside Functions
Functions can have local labels for GOTO/GOSUB:
DEF FN countdown$(n$)
[loop]
IF n$ <= 0 THEN
RETURN "Done!"
END IF
PRINT n$
n$ = n$ - 1
GOTO [loop]
END DEF
PRINT FN countdown$(5)Output:
5
4
3
2
1
Done!
Function Isolation
GOTO and GOSUB inside a function cannot jump outside the function:
[outside_label]
PRINT "Outside"
DEF FN broken$(x$)
GOTO [outside_label] ' ERROR! Label is outside of function
RETURN x$
END DEFThis produces:
GOTO cannot jump outside function: outside_label
This restriction ensures functions are self-contained and predictable.
Practical Examples
Is Even/Odd
DEF FN isEven$(n$)
RETURN MOD(n$, 2) = 0
END DEF
DEF FN isOdd$(n$)
RETURN MOD(n$, 2) = 1
END DEF
FOR i$ = 1 TO 5
IF FN isEven$(i$) THEN
PRINT i$; " is even"
ELSE
PRINT i$; " is odd"
END IF
NEXTOrder of code
Before code can call a user-created function, it must be loaded from the source code.
Wrong
Code below causes error: Error at line 2: Function not found: ADD$
' incorrect way
PRINT FN ADD$(1, 2)
DEF FN ADD$(a$, b$)
RETURN a$ + b$
END DEFRight
Code below is valid
' correct way
DEF FN ADD$(a$, b$)
RETURN a$ + b$
END DEF
PRINT FN ADD$(1, 2)Tip
If you have several of your own functions, write them in their own file and include them in the code using INCLUDE right at the beginning of your program.
Control Flow
IF Statements
Block IF
Multi-line conditional with THEN on its own:
IF score$ >= 90 THEN
PRINT "Grade: A"
PRINT "Excellent!"
END IFIF/ELSE
IF age$ >= 18 THEN
PRINT "Adult"
ELSE
PRINT "Minor"
END IFIF/ELSEIF/ELSE
IF score$ >= 90 THEN
PRINT "A"
ELSEIF score$ >= 80 THEN
PRINT "B"
ELSEIF score$ >= 70 THEN
PRINT "C"
ELSEIF score$ >= 60 THEN
PRINT "D"
ELSE
PRINT "F"
END IFOne-line IF
Jump to label based on condition:
IF lives$ = 0 THEN GOTO [game_over]
IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [continue]
IF ready$ = 1 THEN GOSUB [start_game]FOR Loops
Note: FOR auto-declares the loop variable — no LET needed.
Basic FOR
FOR i$ = 1 TO 10
PRINT i$
NEXTFOR with STEP
FOR i$ = 0 TO 100 STEP 10
PRINT i$
NEXTCounting Down
FOR i$ = 10 TO 1 STEP -1
PRINT i$
NEXT
PRINT "Liftoff!"Nested FOR
FOR row$ = 1 TO 3
FOR col$ = 1 TO 3
PRINT row$; ","; col$; " ";
NEXT
PRINT ""
NEXTLeaving a FOR Early: EXIT FOR
EXIT FOR stops the innermost FOR loop and continues
after its NEXT. The loop variable keeps the value it had
when the loop was left.
FOR i$ = 1 TO 100
IF i$ * i$ > 50 THEN EXIT FOR
NEXT
PRINT "First square over 50: "; i$ ' 8WHILE Loops
Repeat while condition is true:
LET count$ = 0
WHILE count$ < 5
PRINT count$
count$ = count$ + 1
WENDInfinite Loop with Exit Condition: EXIT WHILE
EXIT WHILE stops the innermost WHILE loop and continues
after its WEND.
WHILE 1
LET key$ = INKEY
IF key$ = KEY_ESC# THEN EXIT WHILE
' Game logic here
WEND
PRINT "Goodbye"Notes on EXIT WHILE and EXIT FOR
- They work anywhere inside the loop: in a one-line IF, inside an
IF…END IF block, or inside an inner loop of the other kind.
EXIT WHILEinside a FOR that sits in a WHILE leaves both loops. - Only the innermost loop of the named kind is left. To leave several nested loops at once, use a flag variable.
- Inside
DEF FN, EXIT can only leave loops that are inside the function. EXITwithout a loop of that kind is an error:EXIT WHILE without WHILE.- Prefer EXIT over
GOTOout of a loop. A GOTO leaves the loop’s bookkeeping behind; doing it repeatedly (for example once per frame) slowly fills up memory and can confuse laterNEXTstatements.
Labels and GOTO
Labels are marked with square brackets:
[start]
PRINT "Starting..."
GOTO [main]
[main]
PRINT "Main section"
GOTO [end]
[end]
PRINT "Done"
ENDGOSUB and RETURN
Call a subroutine and return:
PRINT "Before subroutine"
GOSUB [greet]
PRINT "After subroutine"
END
[greet]
PRINT "Hello!"
RETURNNested GOSUB
GOSUB [level1]
END
[level1]
PRINT "Level 1"
GOSUB [level2]
PRINT "Back to Level 1"
RETURN
[level2]
PRINT "Level 2"
RETURNVariables as GOTO/GOSUB targets
A variable or constant containing a label string can be used as a jump target:
LET foo$ = "[start]"
LET bar# = "[jump]"
GOTO foo$
[start]
PRINT "[start]"
GOSUB bar#
PRINT "Ending line"
END
[jump]
PRINT "[jump]"
RETURNFunction Scope and Labels
Inside user-defined functions, GOTO and GOSUB can only jump to labels within the same function:
DEF FN test$(x$)
[local_label]
IF x$ < 10 THEN
x$ = x$ + 1
GOTO [local_label] ' OK - within function
END IF
RETURN x$
END DEF
[outside]
' GOTO [outside] from inside the function above would cause an error
PRINT "Outside"END
Terminates program execution.
IF error$ THEN
PRINT "Error occurred"
END
END IF
PRINT "This runs if no error"SLEEP
Pause execution for specified milliseconds.
PRINT "Wait 2 seconds..."
SLEEP 2000
PRINT "Done!"Line Continuation
Long expressions and statements can be split across multiple lines.
BazzBasic figures this out automatically — there is no special
continuation character to remember (no \, no
_, no &).
A newline is treated as a continuation (instead of ending the statement) when either:
- The previous token cannot legally end an expression — a binary operator, comma, compound-assign, or open paren.
- You are inside an open
( ... )pair.
Operator-driven continuation
Any line ending in an “incomplete” token continues on the next line. Empty lines and trailing comments between the parts are tolerated.
LET total$ = price$ * count$ -
discount$
LET msg$ = "Hello, " +
name$ +
"!"
IF score$ >= 0 AND
score$ <= 100 THEN
PRINT "Valid score"
END IF
LET counter$ +=
step$The full list of operators that trigger continuation: +,
-, *, /, %,
=, <>, <,
<=, >, >=,
AND, OR, +=, -=,
*=, /=, and ,.
Note:
MODis a function (MOD(a, b)), not an operator, so it does not trigger continuation. The symbol%does.
Paren-driven continuation
Anything inside an unmatched ( keeps reading until the
matching ), regardless of newlines:
LET dist$ = DISTANCE(
x1$, y1$,
x2$, y2$
)
LET val$ = MAX(
MIN(100, score$),
0
)
DIM grid$
grid$(0,
0) = "X"Both mechanisms can be combined freely:
LET total$ = (
base$ +
tax$ -
discount$
)Watch out
Forgetting to close a ( makes the lexer keep eating
lines until it finds a matching ) (or runs out of source).
The eventual error message can be far from the actual mistake — count
your parentheses if a long file suddenly stops parsing the way you
expect.
See Also
- Operators — comparison and logical operators
- Input Functions — INKEY, KEYDOWN, WAITKEY
- Statements A-Z — PRINT, INPUT, CLS, etc.
Statements A-Z
Action commands that perform operations. For flow control (IF, FOR, WHILE, GOTO, GOSUB) see Control Flow.
CLS
Clear the screen.
CLSCOLOR
Set text foreground and background colors (0-15 palette).
COLOR 14, 1 ' Yellow text on blue background
PRINT "Colorful!"See also: Graphics Commands
INPUT and LINE INPUT
BazzBasic provides two commands for reading user input from the console.
INPUT
Reads user input, splits on whitespace or comma.
INPUT "prompt", variable$
INPUT "prompt", var1$, var2$, var3$
INPUT variable$ ' Uses "? " as default promptLET firstName$, lastName$
INPUT "Enter your name: ", firstName$, lastName$
' User types: Kristian Virtanen
PRINT firstName$ + " " + lastName$
' Output: Kristian VirtanenLINE INPUT
Reads the entire line including spaces.
LINE INPUT "Enter your name: ", name$
' User types: Kristian Virtanen
PRINT name$
' Output: Kristian VirtanenINPUT and LINE INPUT read from standard
input, so they keep working when input is piped or redirected from a
file (no real console needed).
Comparison
| Feature | INPUT | LINE INPUT |
|---|---|---|
| Reads spaces | No (splits) | Yes |
| Multiple variables | Yes | No |
| Default prompt | “?” | None |
LOCATE
Move cursor to specified position (1-based row and column).
LOCATE 10, 20
PRINT "Positioned text"Output text and values to the screen.
PRINT "Hello, World!"
PRINT 42
PRINT "Value: "; x$
PRINT "A", "B", "C" ' Tab-separated
PRINT "X="; 10; ' No newline at endEscape Characters
| Escape | Result |
|---|---|
\" |
Quote |
"" |
Quote (two quotes inside a string make one) |
\n |
New line |
\t |
Tab |
\r |
Carriage return (back to the start of the line) |
\\ |
Backslash |
PRINT "He said, \"Hello\"" ' Output: He said, "Hello"
PRINT "He said, ""Hello""" ' Output: He said, "Hello"
PRINT "Line1\nLine2"SHELL
Sends a command to the system command interpreter.
Optional timeout parameter in milliseconds (default: 5000).
LET a$ = SHELL("dir *.txt")
PRINT a$
' Custom timeout (2 seconds)
LET a$ = SHELL("dir *.txt", 2000)
PRINT a$SLEEP
Pause execution for specified milliseconds.
PRINT "Wait..."
SLEEP 2000
PRINT "Done!"See Also
- Control Flow — IF, FOR, WHILE, GOTO, GOSUB
- Variables & Constants — LET
- Arrays & JSON — DIM
- Comments — REM and ’
Functions
BazzBasic’s built-in functions are organized into separate pages:
- Math Functions — ABS, SIN, COS, LERP, DISTANCE, PI#, TAU#…
- Fast Trigonometry — FastSin, FastCos, FastRad, lookup tables
- String Functions — LEFT, MID, INSTR, SPLIT, SHA256, BASE64…
- Input Functions — INKEY, KEYDOWN, WAITKEY, MOUSEX/Y, MOUSEWHEEL, GAMEPADS, PADBUTTON, PADAXIS…
- Other Functions — RGB, TIME, TICKS
Math Functions
Looking for modulo (remainder)? It’s the
%operator, not a function — see Operators.10 % 3→1.
ABS(n)
Returns the absolute value of n.
PRINT ABS(1.5) ' 1.5
PRINT ABS(-1.5) ' 1.5ATAN(n)
Returns the arc tangent of a n
PRINT ATAN(1.5) ' 0.982793723247329
PRINT ATAN(-1.5) ' -0.982793723247329ATAN2(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.
PRINT ATAN2(5, 10) ' 0.4636476090008061AU
Astronomical unit in metres: exactly 149597870700 (IAU 2012
definition). Like every built-in constant it cannot be changed:
AU# = 1 and LET AU# = 1 are both errors.
Note: if older code declares its own
AU# with LET, remove that line.
PRINT AU# ' Output: 149597870700
PRINT AU# / 1000 ' Output: 149597870.7 (kilometres)BETWEEN(n, min, max)
Returns true if n is equal or between min and max
BETWEEN(1, 1, 10) ' true
BETWEEN(2, 1, 10) ' true
INBETWEEN(1, 1, 10) ' false
INBETWEEN(2, 1, 10) ' trueUnlike INBETWEEN which returns true if n is not equal and between min and max, BETWEEN returns true if n is equal and between min and max
CINT(n)
The Cint function converts an expression to type Integer.
PRINT CINT(3.7) ' Output: 4
PRINT CINT(3.3) ' Output: 3
PRINT CINT(-3.7) ' Output: -4CEIL(n)
Returns the smallest integer that is greater than or equal to a given number
PRINT CEIL(3.7) ' Output: 4
PRINT CEIL(3.3) ' Output: 4
PRINT CEIL(-3.7) ' Output: -3COS(n)
Returns the cosine of an angle
PRINT COS(0) ' Output: 1
PRINT COS(45) ' Output 0.5253219888177297
PRINT COS(90) ' Output: -0.4480736161291701CLAMP(n, min, max)
If the given parameter n falls below or exceeds the given limit values min or max, it is returned within the limits
LET brightness$ = CLAMP(value$, 20, 255)
' Replaces lines
' IF brightness$ < 20 THEN brightness$ = 20
' IF brightness$ > 255 THEN brightness$ = 255DEG(radians)
Converts radians to degrees.
PRINT DEG(PI#) ' Output: 180
PRINT DEG(HPI#) ' Output: 90
PRINT DEG(2 * PI#) ' Output: 360
' Convert result back to degrees
LET angle_rad$ = 1.5707963267948966
PRINT DEG(angle_rad$) ' Output: 90DISTANCE(x1, y1, x2, y2) or DISTANCE(x1, y1, z1, x2, y2, z2)
Returns the Euclidean distance between two points. Supports both 2D and 3D.
2D mode (4 parameters):
PRINT DISTANCE(0, 0, 3, 4) ' Output: 5 (3-4-5 triangle)
PRINT DISTANCE(10, 20, 40, 60) ' Output: 503D mode (6 parameters):
PRINT DISTANCE(0, 0, 0, 1, 1, 1) ' Output: 1.732... (sqrt of 3)
PRINT DISTANCE(0, 0, 0, 0, 0, 5) ' Output: 5Practical example:
LET playerX$ = 100, playerY$ = 200
LET enemyX$ = 250, enemyY$ = 350
LET dist$ = DISTANCE(playerX$, playerY$, enemyX$, enemyY$)
IF dist$ < 50 THEN
PRINT "Enemy is close!"
END IFEULER
Returns the Euler’s constant, 2.718281828459045
PRINT EULER# ' Output: 2.718281828459045EXP(n)
Exponential (e^n).
PRINT EXP(1) ' Output: 2.718...
PRINT EXP(0) ' Output: 1FLOOR(n)
Rounds down and returns the largest integer
PRINT FLOOR(1.1) ' Output: 1
PRINT FLOOR(1.95) ' Output: 1
PRINT FLOOR(300) ' Output: 300GRAV
Gravitational constant: 6.6743E-11 m^3 kg^-1 s^-2. Like every
built-in constant it cannot be changed: GRAV# = 1 and
LET GRAV# = 1 are both errors.
PRINT GRAV# ' Output: 6.6743E-11
LET force$ = m1$ * m2$ * GRAV# / (r$ * r$) ' Newton's law of gravitationGRAV_E
Standard gravity on Earth (standard acceleration of free fall): 9.80665 m/s^2. Like every built-in constant it cannot be changed.
PRINT GRAV_E# ' Output: 9.80665
LET fallen$ = GRAV_E# / 2 * t$ * t$ ' distance fallen in t$ secondsHPI
Returns half of π (pi/2) ≈ 1.5707963267948966. Equivalent to 90 degrees in radians.
Useful in graphics and game programming where 90-degree angles are common.
PRINT HPI# ' Output: 1.5707963267948966
PRINT DEG(HPI#) ' Output: 90
' Common angles in radians using built-in constants
LET angle_0$ = 0 ' 0 degrees
LET angle_45$ = QPI# ' 45 degrees
LET angle_90$ = HPI# ' 90 degrees
LET angle_180$ = PI# ' 180 degrees
LET angle_270$ = PI# + HPI# ' 270 degrees
LET angle_360$ = TAU# ' 360 degreesINBETWEEN(n, min, max)
Returns true, if n is between min and max and not equal to them
INBETWEEN(1, 1, 10) ' false
INBETWEEN(2, 1, 10) ' true
BETWEEN(1, 1, 10) ' true
BETWEEN(2, 1, 10) ' trueUnlike BETWEEN which returns true if n is equal or between min and max, INBETWEEN returns true if n is not equal and between min and max
INT(n)
Returns the integer part (truncates toward zero).
PRINT INT(3.7) ' Output: 3
PRINT INT(-3.7) ' Output: -3LERP(start, end, t)
Linear interpolation between two values. Returns a value between start and end based on parameter t (0.0 to 1.0).
Parameters: - start - Starting value
(when t = 0) - end - Ending value (when t = 1) -
t - Interpolation factor (0.0 to 1.0) -
t = 0.0 returns start - t = 0.5
returns halfway between - t = 1.0 returns end
Formula:
result = start + (end - start) × t
Basic examples:
PRINT LERP(0, 100, 0) ' Output: 0 (0% of the way)
PRINT LERP(0, 100, 0.5) ' Output: 50 (50% of the way)
PRINT LERP(0, 100, 1) ' Output: 100 (100% of the way)
PRINT LERP(10, 20, 0.25) ' Output: 12.5
PRINT LERP(10, 20, 0.75) ' Output: 17.5Practical examples:
Distance-based brightness (raycasting):
LET maxDist# = 10
LET t$ = CLAMP(distance$ / maxDist#, 0, 1)
LET brightness$ = LERP(255, 20, t$) ' Bright nearby, dark far awaySmooth camera movement:
LET t$ = 0.1 ' 10% closer each frame
cameraX$ = LERP(cameraX$, targetX$, t$)
cameraY$ = LERP(cameraY$, targetY$, t$)LOG(n)
Natural logarithm (base e).
PRINT LOG(2.718) ' Output: 0.999896315728952MAX(n, n)
Return higher one from two numbers
LET A# = 1
LET A$ = 9.8
PRINT MAX(A#, A$) ' Output: 9.8MIN(n, n)
Return smaller one from two numbers
LET A# = 1
LET A$ = 9.8
PRINT MIN(A#, A$) ' Output: 1MOD(n, n)
Return modulus (remainder) of the two numbers
PRINT MOD(10, 3) ' Output: 1
PRINT MOD(100, 20) ' Output: 0
PRINT MOD(10, 0) ' Output: 0 (division by zero gives 0)PHI
Returns the golden ratio φ ≈ 1.618033988749895.
PRINT PHI# ' Output: 1.618033988749895PI
Returns the mathematical constant π (pi) ≈ 3.141592653589793.
PRINT PI# ' Output: 3.141592653589793
LET circumference$ = 2 * PI# * radius$
LET area$ = PI# * radius$ * radius$POW(n, n)
Return a number raised to the power of another number
PRINT POW(3, 3) ' Output: 27
PRINT POW(2, 2) ' Output: 4BazzBasic has no ^ power operator: 2 ^ 8
stops the program before it starts with
Error: Line N: Unexpected character '^' - for powers use POW(a, b).
See Operators.
QPI
Returns a quarter of π (pi/4) ≈ 0.7853981633974483. Equivalent to 45 degrees in radians.
PRINT QPI# ' Output: 0.7853981633974483
PRINT DEG(QPI#) ' Output: 45
LET dx$ = COS(QPI#) ' ~0.707
LET dy$ = SIN(QPI#) ' ~0.707RAD(degrees)
Converts degrees to radians.
PRINT RAD(90) ' Output: 1.5707963267948966 (HPI#)
PRINT RAD(180) ' Output: 3.141592653589793 (PI#)
PRINT RAD(360) ' Output: 6.283185307179586 (TAU#)
PRINT SIN(RAD(90)) ' Output: 1
PRINT COS(RAD(180)) ' Output: -1RND(n)
Returns a random integer from 0 to n-1 or a floating point between 0 and 1.
PRINT RND(10) ' Output: 0-9
PRINT RND(100) ' Output: 0-99
RND(0) ' Float between 0.0 and 1.0 (IE: 0.5841907423666761)
' Dice roll
LET dice$ = RND(6) + 1ROUND(n)
Rounds a number to the nearest integer. Halfway values (x.5) always round away from zero (up for positive numbers, down for negative numbers) — not to the nearest even number.
PRINT ROUND(1.1) ' Output: 1
PRINT ROUND(1.5) ' Output: 2
PRINT ROUND(1.9) ' Output: 2
PRINT ROUND(0.5) ' Output: 1
PRINT ROUND(10.5) ' Output: 11
PRINT ROUND(-0.5) ' Output: -1SGN(n)
Returns the sign: -1, 0, or 1.
PRINT SGN(-5) ' Output: -1
PRINT SGN(0) ' Output: 0
PRINT SGN(5) ' Output: 1SIN(n)
Returns the sine of a number
PRINT SIN(-5) ' Output: 0.9589242746631385
PRINT SIN(0) ' Output: 0
PRINT SIN(5) ' Output: -0.9589242746631385SQR(n)
Returns the square root.
PRINT SQR(0) ' Output: 0
PRINT SQR(5) ' Output: 2.23606797749979
PRINT SQR(9) ' Output: 3TAN(n)
Returns the tangent of the given angle
PRINT TAN(0) ' Output: 0
PRINT TAN(5) ' Output: -3.380515006246586
PRINT TAN(9) ' Output: -0.45231565944180985TAU
Returns τ (tau) = 2π ≈ 6.283185307179586. Equivalent to 360 degrees in radians (a full circle).
PRINT TAU# ' Output: 6.283185307179586
' Full circle loop
FOR angle$ = 0 TO 359
LET rad$ = (angle$ / 360) * TAU#
LET x$ = COS(rad$) * radius$
LET y$ = SIN(rad$) * radius$
NEXT
' All BazzBasic circle constants:
' QPI# = π/4 = 45°
' HPI# = π/2 = 90°
' PI# = π = 180°
' TAU# = 2π = 360°String Functions
ASC(s$) / ASC(s$, pos)
Returns ASCII code of first character, or of the character at 1-based
position pos.
PRINT ASC("A") ' Output: 65
PRINT ASC("Hello") ' Output: 72 (H)
PRINT ASC("Hello", 2) ' Output: 101 (e)
PRINT ASC("Hello", 9) ' Output: 0 (out of range)ASC(s$, pos) gives the same result as
ASC(MID(s$, pos, 1)) but is faster, because no temporary
substring is created. Use it when looping through a string character by
character:
LET text$ = "Hello"
LET sum$ = 0
FOR i$ = 1 TO LEN(text$)
sum$ += ASC(text$, i$)
NEXT
PRINT sum$ ' Output: 500Out of range (pos less than 1 or greater than
LEN(s$)) returns 0, as does an empty
string.
BASE64DECODE(s$) & BASE64ENCODE(s$)
Decodes and encodes Base64
LET encoded$ = BASE64ENCODE("Hello, World!")
PRINT encoded$ ' SGVsbG8sIFdvcmxkIQ==
LET decoded$ = BASE64DECODE(encoded$)
PRINT decoded$ ' Hello, World!CHR(n)
Returns character for ASCII code.
PRINT CHR(65) ' Output: A
PRINT CHR(10) ' Output: (newline)FSTRING(template$)
String interpolation. Substitutes {{-name-}}
placeholders inside the template with the value of variables, constants,
or array elements. Whitespace inside placeholders is trimmed (so
{{- name$ -}} works the same as {{-name$-}}).
Numbers are auto-converted to strings.
Placeholder forms: - {{-var$-}} —
variable - {{-CONST#-}} — constant -
{{-arr$(0)-}} — array element with numeric index -
{{-arr$(i$)-}} or {{-arr$(KEY#)-}} — array
element where the index comes from a variable / constant (must end in
$ or #) - {{-arr$(name)-}} —
array element with literal string key (matches what was set via
arr$("name") = ...) - {{-arr$(0, i$)-}} —
multidimensional, mixed literal and variable indices
Notes: - No expressions, arithmetic, or function
calls are allowed inside placeholders. Pre-compute into a variable
first. - A bare identifier without $ / #
suffix inside an array index is treated as a literal string key. -
Unknown variable, missing -}}, or empty placeholder halts
execution with a line-numbered error. - The literal sequence
{{-...-}} is reserved — FSTRING will always try to resolve
it.
LET name$ = "Krisu"
LET LEVEL# = 5
PRINT FSTRING("Hello {{-name$-}}, level {{-LEVEL#-}}")
' Output: Hello Krisu, level 5
DIM player$
player$("name") = "Krisu"
player$("level") = 99
PRINT FSTRING("{{-player$(name)-}} is level {{-player$(level)-}}")
' Output: Krisu is level 99
DIM grid$
grid$(0, 0) = "X"
grid$(0, 1) = "O"
LET row$ = 0
PRINT FSTRING("[{{-grid$(row$, 0)-}}{{-grid$(row$, 1)-}}]")
' Output: [XO]INSTR(s$, search$) or INSTR(start, s$, search$)
Finds position of substring (1-based, 0 if not found).
' In default mode, INSTR is case-sensitive
PRINT INSTR("Hello World", "World") ' returns 7
PRINT INSTR("Hello World", "HELLO") ' returns 0
' Case-insensitive mode.
PRINT INSTR("Hello World", "world", 0) ' returns 7
' Case-sensitive mode, same as default mode
PRINT INSTR("Hello World", "world", 1) ' returns 0With a start position — INSTR(start, s$, search$) — a
start less than 1 or greater than LEN(s$)
returns 0.
Note: = ignores case between strings. To compare two
strings exactly, use SAME(a$, b$) (below), see also Comparing text.
INVERT(s$)
Inverts a string
PRINT INVERT("Hello World") ' Output: dlroW olleHLCASE(s$)
Converts to lowercase.
PRINT LCASE("Hello") ' Output: helloLEFT(s$, n)
Returns first n characters.
PRINT LEFT("Hello World", 5) ' Output: Hello
PRINT LEFT("abc", 99) ' Output: abc (n past the end gives the whole string)
PRINT "[" + LEFT("abc", 0) + "]" ' Output: [] (n <= 0 gives an empty string)n less than or equal to 0 returns "";
n greater than LEN(s$) returns the whole
string.
LEN(s$)
Returns string length.
PRINT LEN("Hello") ' Output: 5
PRINT LEN("") ' Output: 0LTRIM(s$)
Removes blank characters from the left of the text
PRINT LTRIM(" Hello World") ' Output: Hello WorldMID(s$, start) or MID(s$, start, length)
Returns substring starting at position (1-based).
PRINT MID("Hello World", 7) ' Output: World
PRINT MID("Hello World", 7, 3) ' Output: Wor
PRINT MID("Hello World", 1, 5) ' Output: Hello
PRINT MID("abc", 2, 999) ' Output: bc (length past the end clamps to the tail)
PRINT "[" + MID("abc", 0, 2) + "]" ' Output: [] (start < 1 or > LEN gives an empty string)
PRINT MID("abc", 2, -1) ' Error at line N: MID: length must be 0 or more, got -1A start less than 1 or greater than LEN(s$)
returns "". A length less than 0 stops the
program with
Error at line N: MID: length must be 0 or more, got -1
(exit code 1); a length past the end of the string clamps
to the tail, so MID("abc", 2, 999999999999) gives
"bc".
REPEAT(s$, n)
Repeats the text requested times
LET a$ = REPEAT("Foo", 10)
PRINT a$ ' Output: FooFooFooFooFooFooFooFooFooFoo
PRINT "[" + REPEAT("ab", 0) + "]" ' Output: [] (n <= 0 gives an empty string)n less than or equal to 0, or an empty string, returns
"". If the result would be longer than 2147483647
characters, the program stops with
Error at line N: REPEAT: result too large (4000000000 characters)
(exit code 1).
REPLACE(s$, a$, b$)
Replaces a$ with b$ from s$
LET text$ = "Hello World"
LET result$ = REPLACE(text$, "World", "BazzBasic")
PRINT result$ ' "Hello BazzBasic"RIGHT(s$, n)
Returns last n characters.
PRINT RIGHT("Hello World", 5) ' Output: World
PRINT RIGHT("abc", 99) ' Output: abc (n past the end gives the whole string)
PRINT "[" + RIGHT("abc", 0) + "]" ' Output: [] (n <= 0 gives an empty string)n less than or equal to 0 returns "";
n greater than LEN(s$) returns the whole
string.
RTRIM(s$)
Removes blank characters from the right of the text
LET a$ = "Foo "
LET b$ = "Bar"
a$ = RTRIM(a$)
PRINT a$ + b$ ' Output: FooBarSAME(a$, b$)
Returns 1 if the two texts are identical, character for
character and case included, otherwise 0. Added in version
1.7.
PRINT SAME("Secret1", "Secret1") ' Output: 1
PRINT SAME("Secret1", "secret1") ' Output: 0
PRINT SAME("", "") ' Output: 1= ignores case, SAME does not, so use
SAME for passwords, keys and IDs. INPUT and
LINE INPUT always store text, so SAME compares
exactly what was typed:
LET pass$ = "Secret1"
LINE INPUT "Password: ", input$
IF SAME(pass$, input$) THEN PRINT "Welcome" ELSE PRINT "Wrong password"
' User types: secret1
' Output: Wrong passwordNumbers are compared in their text form: SAME(1, "1") is
1, but SAME("1.0", 1) and
SAME(-0, 0) are 0. For numbers use
=.
SHA256(s$)
Creates SHA256 hash from a string
LET hash$ = SHA256("password123")
PRINT hash$ ' ef92b778... (64-char lowercase hex)SPLIT(arr$, s$, sep$)
Splits string into array according to separator
DIM parts$
LET count$ = SPLIT(parts$, "apple,banana,orange", ",")
PRINT "Parts: "; count$
PRINT parts$(0) ' "apple"
PRINT parts$(1) ' "banana"
PRINT parts$(2) ' "orange"Returns the number of parts and stores them at keys 0 to
count - 1. The array is emptied first, so splitting again
into the same array leaves no old parts behind.
SRAND(n)
Returns random string length of n from allowed chars.
Allowed chars:
*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&/{([)]=}?+-_*
(81 characters, each equally likely)
PRINT SRAND(10) ' Output example: noAR1S-Qw1
PRINT SRAND(0) ' Output: (empty string, nothing printed)
PRINT LEN(SRAND(3.7)) ' Output: 3
PRINT SRAND(-1) ' Error at line 4: SRAND: length must be 0 or more, got -1n must be zero or more. The decimal part is dropped:
SRAND(3.7) gives 3 characters. SRAND(0)
returns an empty string. A negative n stops the program
with an error, and so does a length too large for memory
(SRAND: length 2147483647 is too large).
STR(n)
Converts number to string.
LET s$ = STR(42)
PRINT "Value: " + s$ ' Output: Value: 42TRIM(s$)
Removes blank characters from start and end of text
LET a$ = " Foo "
LET b$ = " Bar "
a$ = TRIM(a$)
b$ = TRIM(b$)
PRINT a$ + b$ ' Output: FooBarUCASE(s$)
Converts to uppercase.
PRINT UCASE("Hello") ' Output: HELLOVAL(s$)
Converts string to number.
LET n$ = VAL("42")
PRINT n$ + 8 ' Output: 50Input Functions
INKEY
Returns current key press (non-blocking). Returns 0 if no key pressed.
[loop]
LET k$ = INKEY
IF k$ = 0 THEN GOTO [loop]
IF k$ = KEY_ESC# THEN END
PRINT "Key code: "; k$
GOTO [loop]Letters always return the uppercase code, whether Shift or Caps Lock
is on or not: both “a” and “A” return KEY_A# (65).
Special keys return values of 256 or more: - Arrow keys: KEY_UP#, KEY_DOWN#, KEY_LEFT#, KEY_RIGHT# - Function keys: KEY_F1# through KEY_F12# - Numpad keys (graphics screen): KEY_NUMPAD0# through KEY_NUMPAD9#, KEY_NUMPAD_PLUS#, KEY_NUMPAD_MINUS#, KEY_NUMPAD_MUL#, KEY_NUMPAD_DIV#, KEY_NUMPAD_DOT#
Numpad Enter returns KEY_ENTER#, the same as the main
Enter key.
INKEY reads one key at a time. Each call takes the
key away, so a second INKEY in the same loop pass returns
0. Store the value once and compare the variable:
' WRONG - the second INKEY never sees the key
IF INKEY = KEY_A# THEN speed$ = speed$ + 1
IF INKEY = KEY_S# THEN speed$ = speed$ - 1
' RIGHT
LET k$ = INKEY
IF k$ = KEY_A# THEN speed$ = speed$ + 1
IF k$ = KEY_S# THEN speed$ = speed$ - 1INKEY is not the best way to read game controls. It
is fine for simple polling: “press any key”, Esc to quit, menus in the
console. In a graphics game loop, INKEY keeps only the last key pressed
since the previous INKEY call. If another key is pressed
before the next call, the earlier press is replaced and lost. A slow
frame makes this more likely. Use KEYDOWN for controls and
WAITKEY to wait for a key.
KEYDOWN
Read key states via key constants
Note: KEYDOWN is available only when the graphics
screen is used. Not via console
Letter, digit and punctuation constants follow the key’s label on the
user’s keyboard layout, the same way as INKEY:
KEYDOWN(KEY_A#) is TRUE while the key that types “a” is
held. Arrow keys, function keys, numpad and modifier keys are the same
on every layout.
REM KEYDOWN Test
SCREEN 12
LET x$ = 320
LET y$ = 240
WHILE INKEY <> KEY_ESC#
SCREENLOCK ON
LINE (0,0)-(640,480), 0, BF
IF KEYDOWN(KEY_W#) THEN y$ = y$ - 2
IF KEYDOWN(KEY_S#) THEN y$ = y$ + 2
IF KEYDOWN(KEY_A#) THEN x$ = x$ - 2
IF KEYDOWN(KEY_D#) THEN x$ = x$ + 2
IF KEYDOWN(KEY_LSHIFT#) THEN
CIRCLE (x$, y$), 20, RGB(255, 0, 0), 1
ELSE
CIRCLE (x$, y$), 10, RGB(0, 255, 0), 1
END IF
LOCATE 1, 1
COLOR 15, 0
PRINT "WASD=Move SHIFT=Big ESC=Quit"
LOCATE 2, 1
PRINT "X:"; x$; " Y:"; y$; " "
SCREENLOCK OFF
SLEEP 16
WEND
ENDKEYDOWN is TRUE on every loop pass while the key is
held. To react once per press (fire, jump, menu choice), remember the
previous state:
' One action per press: holding SPACE counts only once
SCREEN 12
LET shots$ = 0
LET fireNow$ = FALSE
LET fireWas$ = FALSE
WHILE INKEY <> KEY_ESC#
fireNow$ = KEYDOWN(KEY_SPACE#)
IF fireNow$ AND NOT fireWas$ THEN shots$ = shots$ + 1
fireWas$ = fireNow$
SCREENLOCK ON
LOCATE 1, 1
PRINT "SPACE=Fire ESC=Quit Shots: "; shots$; " "
SCREENLOCK OFF
WEND
ENDWAITKEY
Halts execution until one of the specified keys is pressed. Returns the key value.
' Wait for ENTER only
PRINT "Press ENTER to continue"
LET foo$ = WAITKEY(KEY_ENTER#)
' Wait for any of several keys, capture result
PRINT "Press A, B or ESC"
LET k$ = WAITKEY(KEY_A#, KEY_B#, KEY_ESC#)
PRINT "You pressed: "; k$
' Wait for any key
PRINT "Press any key..."
LET k$ = WAITKEY()
PRINT "Key value: "; k$| Feature | INKEY | KEYDOWN | WAITKEY |
|---|---|---|---|
| Blocking | No | No | Yes |
| Returns | Key value or 0 | TRUE/FALSE | Key value |
| Use case | Simple polling, Esc to quit | Game controls, held keys | Menus, pauses |
Keyboard layouts and portable controls
People run your program with different keyboard layouts (Finnish, US, German, French…). Some keys give the same value everywhere, some do not.
Same on every layout (safe for controls): - Letters
KEY_A#…KEY_Z# and digits
KEY_0#…KEY_9# (they follow the key’s label, so
KEY_A# is always the key marked “A”) - Arrows,
KEY_SPACE#, KEY_ENTER#, KEY_ESC#,
KEY_TAB#, KEY_BACKSPACE#,
Insert/Delete/Home/End/PgUp/PgDn - Function keys
KEY_F1#…KEY_F12# - Numpad keys
KEY_NUMPAD0#…KEY_NUMPAD9#,
KEY_NUMPAD_PLUS#, KEY_NUMPAD_MINUS#,
KEY_NUMPAD_MUL#, KEY_NUMPAD_DIV#,
KEY_NUMPAD_DOT# (graphics screen) - Modifier keys
(KEY_LSHIFT#, KEY_LCTRL#, …)
Depends on the layout (avoid for controls): -
Punctuation on the main keyboard: + - = , . / ; [ ] \ and
the matching KEY_*# constants. In graphics mode INKEY and
KEYDOWN see the key, not Shift or AltGr. On a US keyboard “+” is Shift
plus the “=” key, so INKEY returns ASC("="),
never ASC("+"). On a Finnish keyboard “=” and “/” need
Shift, so KEY_EQUALS# and KEY_SLASH# cannot be
relied on.
Tip: For speed, zoom or volume controls, use letters (for example A/S) or the numpad
+/-keys instead of main-keyboard+and-.
' Speed control that works on every keyboard
LET k$ = INKEY
IF k$ = KEY_A# OR k$ = KEY_NUMPAD_PLUS# THEN speed$ = speed$ + 1
IF k$ = KEY_S# OR k$ = KEY_NUMPAD_MINUS# THEN speed$ = speed$ - 1Console mode differs: without a graphics screen,
INKEY and WAITKEY return the character that was actually typed (Shift
and AltGr included), except for letters (always uppercase codes) and the
special keys listed above. Numpad keys return the typed digit or
operator, not the KEY_NUMPAD*# values. KEYDOWN is not
available in console mode.
No real console (redirected stdin/stdout): console
keyboard and screen commands (INKEY, WAITKEY,
SLEEP key-wait, CLS, CURPOS) need
a real console; with redirected input/output they stop with a
line-numbered Error at line N: ... and exit code 1.
INPUT / LINE INPUT also reads piped stdin and
keeps working.
CURPOS
Returns the current cursor position. Useful for reading where the cursor is after PRINT or LOCATE.
LOCATE 5, 10
PRINT "Hello"
PRINT CURPOS("row") ' Output: 5
PRINT CURPOS("col") ' Output: 15 (10 + 5 chars of "Hello")| Parameter | Returns |
|---|---|
"row" |
Current cursor row (1-based) |
"col" |
Current cursor column (1-based) |
MOUSEX, MOUSEY
Note: Only available when graphics screen is open.
Returns mouse cursor position.
SCREEN 12
[loop]
LOCATE 1, 1
PRINT "X:"; MOUSEX; " Y:"; MOUSEY; " "
GOTO [loop]MOUSELEFT, MOUSERIGHT, MOUSEMIDDLE
Note: Only available when graphics screen is open.
Returns 1 if the specified mouse button is currently pressed, 0 otherwise.
IF MOUSELEFT THEN PRINT "Left clicked"
IF MOUSERIGHT THEN PRINT "Right clicked"
IF MOUSEMIDDLE THEN PRINT "Middle clicked"MOUSEWHEEL
Note: Only available when graphics screen is open. In console mode it returns 0.
Returns how many notches the mouse wheel has been rolled since the
previous MOUSEWHEEL call, then starts counting again from
0. Added in v1.8.
- Positive = rolled away from you (up), negative = rolled toward you (down), 0 = no movement.
MOUSEWHEELandMOUSEWHEEL()both work.MOUSEWHEEL(1)is an error.- Rolls made while the program waits in
SLEEP,WAITKEYorINPUTare not lost. - The first call returns what was rolled since
SCREEN. Call it once after setup if you want to start from 0. A newSCREENstarts from 0. - Touchpads and smooth-scrolling wheels work too: small movements add up to whole notches.
- Only the vertical wheel is read. Sideways scrolling (tilt wheel) is not supported.
Store the value in a variable: a second MOUSEWHEEL in
the same loop pass returns 0.
' Roll the mouse wheel to zoom, ESC quits
SCREEN 12
LET zoom$ = 1
LET w$ = 0
WHILE INKEY <> KEY_ESC#
w$ = MOUSEWHEEL
IF w$ <> 0 THEN zoom$ = zoom$ * POW(1.25, w$)
LOCATE 1, 1
PRINT "Zoom: "; zoom$; " "
SLEEP 16
WEND
ENDMOUSEHIDE & MOUSESHOW
In graphics screen, MOUSEHIDE hides the mouse cursor while MOUSESHOW will bring it back.
MOUSEHIDE ' hides mouse
SLEEP 5000
MOUSESHOW ' brings it backGamepad
BazzBasic reads game controllers (Xbox, PlayStation, Switch Pro and most compatible pads) through SDL2. USB and Bluetooth both work. Added in v1.5.
- Works in console and graphics mode. No
SCREENneeded. - Pads are numbered from 0. Up to 8 pads. A pad gets its number when it connects and keeps it while connected, so player 2 does not become player 1 if player 1’s pad drops.
- A pad that is not connected reads as “nothing pressed”:
PADBUTTONreturns FALSE,PADAXISreturns 0 andPADNAMEreturns"". No error, so a game keeps running if a pad is unplugged. - Pads can be plugged in or switched on while the program runs. They are found within about a quarter of a second.
| Function | Returns |
|---|---|
GAMEPADS() |
Number of connected pads |
PADBUTTON(pad, button) |
TRUE while the button is held |
PADAXIS(pad, axis) |
Sticks -1.0 … 1.0, triggers 0.0 … 1.0 |
PADNAME(pad) |
Controller name, e.g. "PS4 Controller" |
PADRUMBLE pad, strength, ms |
(statement) Vibrate, strength 0.0 … 1.0 |
GAMEPADS
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.
Returns how many pads are connected. Parentheses are optional.
IF GAMEPADS() = 0 THEN PRINT "Connect a gamepad"
PRINT "Pads: "; GAMEPADS()
IF GAMEPADS() > 0 THEN PRINT "Pad 0: "; PADNAME(0)PADBUTTON
Returns TRUE while the button is held down, like KEYDOWN
for the keyboard.
Button constants use the Xbox layout. On PlayStation pads:
PAD_A# = Cross, PAD_B# = Circle,
PAD_X# = Square, PAD_Y# = Triangle,
PAD_BACK# = Share, PAD_START# = Options.
| Constant | Button |
|---|---|
PAD_A#, PAD_B#, PAD_X#,
PAD_Y# |
Face buttons |
PAD_UP#, PAD_DOWN#,
PAD_LEFT#, PAD_RIGHT# |
D-pad |
PAD_LB#, PAD_RB# |
Upper shoulder buttons (L1 / R1) |
PAD_LSTICK#, PAD_RSTICK# |
Pressing a stick down (L3 / R3) |
PAD_BACK#, PAD_START#,
PAD_GUIDE# |
Back/Share, Start/Options, Xbox/PS button |
PAD_MISC# |
Extra button (Xbox Series Share, PS5 mic, Switch Capture) |
PAD_TOUCHPAD# |
PlayStation touchpad click |
Buttons 16–19 are the back paddles on pads that have them (Xbox Elite). A button number outside 0–20 is an error.
The lower shoulder buttons (L2 / R2) are triggers, not buttons. Read them with
PADAXIS(pad, PAD_LT#)andPADAXIS(pad, PAD_RT#). Do not usePADBUTTON(0, PAD_LT#): the constants are just numbers, so it reads a different button (Back) without an error. To treat a trigger as a button, usePADAXIS(0, PAD_RT#) > 0.5.
PADBUTTON is TRUE on every loop pass while the button is
held. To react once per press, remember the previous state:
LET jumpWas$ = FALSE
LET jumpNow$ = FALSE
WHILE TRUE
jumpNow$ = PADBUTTON(0, PAD_A#)
IF jumpNow$ AND NOT jumpWas$ THEN PRINT "Jump!" ' only on the press
jumpWas$ = jumpNow$
SLEEP 16
WENDPADAXIS
Returns the position of a stick or trigger.
| Constant | Axis | Range |
|---|---|---|
PAD_LX#, PAD_LY# |
Left stick | -1.0 … 1.0 |
PAD_RX#, PAD_RY# |
Right stick | -1.0 … 1.0 |
PAD_LT#, PAD_RT# |
Triggers (L2 / R2) | 0.0 … 1.0 |
- X: negative = left, positive = right. Y: negative = up, positive = down, the same direction as screen coordinates.
- A small dead zone is built in: a stick that rests slightly off-centre still reads exactly 0, so things do not drift by themselves.
- An axis number outside 0–5 is an error.
' Analog movement: small push = slow, full push = fast
x$ = x$ + PADAXIS(0, PAD_LX#) * SPEED#
y$ = y$ + PADAXIS(0, PAD_LY#) * SPEED#
' Use a stick like a D-pad
IF PADAXIS(0, PAD_LX#) < -0.5 THEN PRINT "Left"PADNAME
Returns the controller’s name, or "" if the pad is not
connected.
PRINT PADNAME(0) ' Output e.g.: PS4 ControllerMany third-party pads report themselves as a PS4 or Xbox controller. That is normal and the buttons still map correctly.
PADRUMBLE
Vibrates the pad. strength is 0.0 … 1.0, ms
is the duration in milliseconds. The program does not wait for it. Pads
without vibration ignore it. Parentheses are optional.
PADRUMBLE 0, 0.5, 200 ' half power for 0.2 seconds
PADRUMBLE(0, 1, 500) ' same thing with parenthesesExample: pad and keyboard together
SCREEN 0, 640, 480, "Gamepad demo"
LET x$ = 320
LET y$ = 240
LET dx$, dy$
WHILE INKEY <> KEY_ESC# AND NOT PADBUTTON(0, PAD_BACK#)
dx$ = PADAXIS(0, PAD_LX#)
dy$ = PADAXIS(0, PAD_LY#)
IF PADBUTTON(0, PAD_LEFT#) OR KEYDOWN(KEY_LEFT#) THEN dx$ = -1
IF PADBUTTON(0, PAD_RIGHT#) OR KEYDOWN(KEY_RIGHT#) THEN dx$ = 1
IF PADBUTTON(0, PAD_UP#) OR KEYDOWN(KEY_UP#) THEN dy$ = -1
IF PADBUTTON(0, PAD_DOWN#) OR KEYDOWN(KEY_DOWN#) THEN dy$ = 1
x$ = CLAMP(x$ + dx$ * 5, 10, 629)
y$ = CLAMP(y$ + dy$ * 5, 10, 469)
SCREENLOCK ON
LINE (0,0)-(639,479), 0, BF
CIRCLE (x$, y$), 10, RGB(0, 255, 0), 1
SCREENLOCK OFF
SLEEP 16
WEND
ENDMore examples: Examples/GamePad/.
Troubleshooting
GAMEPADS()returns 0: check that Windows sees the pad (Settings → Bluetooth & devices). A Bluetooth pad must be paired and switched on. Try a USB cable to rule out Bluetooth.- A stick or button does nothing: many third-party
pads have a MODE or ANALOG button that turns the right stick into a
D-pad or switches the sticks off. Run
Examples/GamePad/gamepad_test.basto see exactly what the program receives. - Tools such as DS4Windows or Steam Input can hide or re-map the real pad. Close them if buttons come out wrong.
Fast Trigonometry (Lookup Tables)
For graphics-intensive applications (games, raycasting, animations),
BazzBasic provides fast trigonometric functions using pre-calculated
lookup tables. These are significantly faster than standard
SIN/COS functions but have 1-degree
precision.
Performance: ~20x faster than
SIN(RAD(x)) for integer degree values.
Memory: Uses ~5.6 KB when enabled (360 values × 2 tables × 8 bytes).
FastTrig(enable)
Enables or disables fast trigonometry lookup tables.
Parameters: - TRUE (or any non-zero
value) - Creates lookup tables - FALSE (or 0) - Destroys
lookup tables and frees memory
Important: Must call FastTrig(TRUE)
before using FastSin, FastCos, or
FastRad.
FastTrig(TRUE)
LET x$ = FastCos(45)
LET y$ = FastSin(45)
FastTrig(FALSE)FastSin(angle)
Returns the sine of an angle (in degrees) using a lookup table. Angle is automatically normalized to 0-359. Precision: 1 degree.
FastTrig(TRUE)
PRINT FastSin(0) ' Output: 0
PRINT FastSin(90) ' Output: 1
PRINT FastSin(180) ' Output: 0
PRINT FastSin(270) ' Output: -1
' Angles are automatically wrapped
PRINT FastSin(450) ' Same as FastSin(90) = 1
PRINT FastSin(-90) ' Same as FastSin(270) = -1
FastTrig(FALSE)FastCos(angle)
Returns the cosine of an angle (in degrees) using a lookup table. Angle is automatically normalized to 0-359. Precision: 1 degree.
FastTrig(TRUE)
PRINT FastCos(0) ' Output: 1
PRINT FastCos(90) ' Output: 0
PRINT FastCos(180) ' Output: -1
PRINT FastCos(270) ' Output: 0
FOR angle$ = 0 TO 359
LET dx$ = FastCos(angle$)
LET dy$ = FastSin(angle$)
' Cast ray in direction (dx, dy)
NEXT
FastTrig(FALSE)FastRad(angle)
Converts degrees to radians using an optimized formula. Angle is automatically normalized to 0-359 before conversion — so a full turn (360) wraps to 0.
Note: Does not require FastTrig(TRUE).
Unlike FastSin/FastCos, this function never
checks whether fast trig tables are enabled — it works standalone.
Not the same as RAD(angle):
RAD() does not normalize and converts the raw angle as
given (RAD(360) = 6.283185307179586, i.e. 2×PI).
FastRad() always normalizes first, so
FastRad(360) = FastRad(0) = 0. Pick
RAD() if you need the literal, un-wrapped radian value.
PRINT FastRad(90) ' Output: 1.5707963267948966 (HPI)
PRINT FastRad(180) ' Output: 3.141592653589793 (PI)
PRINT FastRad(360) ' Output: 0 (wraps to angle 0, NOT 2*PI)
PRINT FastRad(450) ' Output: 1.5707963267948966 (same as FastRad(90))When to Use Fast Trig
Use FastTrig when: - Rendering graphics at high
frame rates (60+ FPS) - Raycasting or ray tracing - Rotating sprites or
shapes - Particle systems with many particles - Any loop that calls
SIN/COS hundreds of times per frame
Use regular SIN/COS when: - Scientific calculations requiring high precision - One-time calculations - Angles are not in integer degrees
Color Functions
RGB(r, g, b)
Creates a color value from red, green, and blue components (0-255 each).
LET red$ = RGB(255, 0, 0)
LET green$ = RGB(0, 255, 0)
LET blue$ = RGB(0, 0, 255)
LET white$ = RGB(255, 255, 255)
LET black$ = RGB(0, 0, 0)
LET purple$ = RGB(128, 0, 128)
PSET 100, 100, RGB(255, 128, 0) ' Orange pixel
LINE (0, 0)-(100, 100), RGB(0, 255, 0) ' Green line
CIRCLE 200, 200, 50, RGB(255, 0, 0) ' Red circleTip: Store frequently used colors in constants for better performance:
LET COLOR_PLAYER# = RGB(0, 128, 255)
LET COLOR_ENEMY# = RGB(255, 64, 64)
LET COLOR_BG# = RGB(32, 32, 48)Time Functions
TIME(format$)
Returns current date/time as a formatted string. Uses .NET DateTime format strings.
PRINT TIME() ' Default: "16:30:45"
PRINT TIME("HH:mm:ss") ' "16:30:45"
PRINT TIME("dd.MM.yyyy") ' "09.01.2026"
PRINT TIME("yyyy-MM-dd") ' "2026-01-09"
PRINT TIME("dddd") ' "Friday"
PRINT TIME("MMMM") ' "January"
PRINT TIME("dd MMMM yyyy") ' "09 January 2026"
PRINT TIME("HH:mm") ' "16:30"Note:
:in the format follows the Windows regional settings — on a Finnish systemTIME()andTIME("HH:mm:ss")print18.19.08(dot as the time separator). For a fixed colon on every system, quote it:TIME("HH':'mm':'ss")prints18:19:08.
Common format codes: | Code | Description | Example | |——|————-|———| | HH | Hour (00-23) | 16 | | mm | Minutes | 30 | | ss | Seconds | 45 | | dd | Day | 09 | | MM | Month (number) | 01 | | MMM | Month (short) | Jan | | MMMM | Month (full) | January | | yy | Year (2 digits) | 26 | | yyyy | Year (4 digits) | 2026 | | ddd | Weekday (short) | Fri | | dddd | Weekday (full) | Friday |
TICKS
Returns milliseconds elapsed since program started. Useful for timing, animations, and game loops.
LET start$ = TICKS
FOR i$ = 1 TO 10000
LET x$ = x$ + 1
NEXT
LET elapsed$ = TICKS - start$
PRINT "Time taken: "; elapsed$; " ms"Game loop timing example:
SCREEN 12
LET lastFrame$ = TICKS
LET frameTime# = 16 ' ~60 FPS
[gameloop]
LET now$ = TICKS
IF now$ - lastFrame$ >= frameTime# THEN
' Update game logic here
lastFrame$ = now$
END IF
IF INKEY = KEY_ESC# THEN END
GOTO [gameloop]Console Functions
GETCONSOLE(row, col, type)
Reads a character or color from a specific position on the console screen. Console only — not available in graphics mode.
Parameters: - row — row (1-based) -
col — column (1-based) - type — 0 = character
(as ASCII code), 1 = foreground color, 2 = background color
CLS
COLOR 11, 1
PRINT "abcdefghi"
PRINT "ABCDEFGHI"
COLOR 1, 9
PRINT "987654321"
COLOR 15, 0
PRINT "Row 2, col 5 char is: " + CHR(GETCONSOLE(2, 5, 0)) ' Output: E
PRINT "Row 1, col 2 foreground color: " + GETCONSOLE(1, 2, 1) ' Output: 11
PRINT "Row 1, col 3 background color: " + GETCONSOLE(1, 3, 2) ' Output: 1Command Line Arguments
ARGCOUNT
Return the amount of arguments passed to program.
' BazzBasic.exe test.bas arg1 arg2 (a packaged exe works the same: test.exe arg1 arg2)
PRINT ARGCOUNT ' 2ARGS()
Returns certain argument, if passed.
' BazzBasic.exe test.bas arg1 arg2
PRINT ARGS(0)
PRINT ARGS(1)
' Output:
' arg1
' arg2Important
- Always check with ARGCOUNT first, is there arguments passed
- ARGCOUNT gives the amount of arguments but ARGS() places first argument in ARGS(0), not in ARGS(1).
- Packaged exes (made with
-exe) behave identically:test.exe arg1 arg2gives ARGCOUNT = 2 and ARGS(0) = “arg1” - Inside a packaged exe, interpreter flags like
-vare not special - they arrive as ordinary ARGS() strings (prog.exe -v-> ARGS(0) = “-v”)
Variable Functions
ISSET(name)
Returns 1 if the named variable
($) or constant (#) is
declared, 0 otherwise. Useful for checking whether
LET has run on a code path, or for branching on
configuration values.
ISSET only sees scalar variables and constants. Arrays
and array elements are stored in a separate namespace and always return
0 — use the array-specific functions if you need to check
those.
LET a$ = "hello"
LET b$ ' declared with no value
LET MAX# = 100
PRINT ISSET(a$) ' 1
PRINT ISSET(b$) ' 1 (LET declares it even without a value)
PRINT ISSET(MAX#) ' 1
PRINT ISSET(undef$) ' 0
PRINT ISSET(UNDEF#) ' 0Suffix matters. a$ and A#
are two different names — $ and # are part of
the identifier:
LET a$ = "foo"
PRINT ISSET(a$) ' 1
PRINT ISSET(A#) ' 0 - the constant A# does not existArrays return 0. The array name is not a scalar variable, and array elements are not scalars either:
DIM arr$
arr$(0) = "zero"
PRINT ISSET(arr$) ' 0
PRINT ISSET(arr$(0)) ' 0
PRINT ISSET(arr$(99)) ' 0Typical use — guarding optional setup:
IF NOT ISSET(playerName$) THEN
LET playerName$ = "Anonymous"
END IFImportant
ISSETaccepts only a single bare variable or constant name.ISSET(a$ + b$),ISSET("a$"),ISSET(42), andISSET()are all errors.- The argument is not evaluated —
ISSET(undef$)is safe and returns0, it does not raise an “undefined variable” error.
File handling
BazzBasic includes a simple but powerful file system for reading and writing text files, enabling games to save scores, settings, and game state.
Overview
The file system allows you to: - Read text file contents as strings - Write or overwrite files - Append content to existing files - Check if files exist - Delete files - List the files in a folder - Work with both relative and absolute paths - Automatically create directories as needed
Supported File Operations
- Text file reading - Load entire file as string
- Text file writing - Create or overwrite files
- Text file appending - Add content to end of files
- File existence checking - Verify files exist before operations
- File deletion - Remove files from disk
- Automatic directory creation - Parent directories created automatically
File Functions
FILEREAD(filepath$)
Reads the entire contents of a text file and returns it as a string or array.
Returns: String - Complete file contents, or empty string if file doesn’t exist or error occurs
Syntax:
content$ = FILEREAD("path/to/file.txt")Example with variable:
LET config$
config$ = FILEREAD("settings.txt")
IF LEN(config$) > 0 THEN
PRINT "Config loaded: "; config$
ELSE
PRINT "Config file not found"
ENDIFExample with array:
LET FILENAME# = "array.txt"
DIM a$
a$("first") = 1
a$("second") = 2
a$("third") = 3
a$("fourth") = "Four"
a$("fourth", "temp") = "Temp"
FILEWRITE FILENAME#, a$
DIM b$ = FILEREAD(FILENAME#)
PRINT b$("fourth", "temp")Notes: - Returns empty string on error (no exception thrown) - Handles various text encodings automatically - Best for small to medium-sized text files - Line breaks are preserved in the returned string
FILEEXISTS(filepath$)
Checks whether a file exists at the specified path.
Returns: Number - 1 if file exists, 0 if not
Syntax:
LET exists# = FILEEXISTS("path/to/file.txt")Example:
IF FILEEXISTS("highscore.txt") = 1 THEN
PRINT "Loading existing scores..."
LET scores$ = FILEREAD("highscore.txt")
ELSE
PRINT "No saved scores found"
LET scores$ = "0"
ENDIFNotes: - Safe to call on any path - Returns 0 if path doesn’t exist or access is denied - Use before FILEREAD to avoid empty string results - Useful for conditional file operations
File Commands
FILEWRITE filepath$, content$
Writes content to a file, creating it if it doesn’t exist or overwriting it completely if it does.
Syntax:
FILEWRITE filepath$, content$Example with string:
LET score$ = 12345
LET playerName$ = "Alice"
LET saveData$ = playerName$ + "\n" + STR(score$)
FILEWRITE "savegame.txt", saveData$
PRINT "Game saved!"Example with array:
LET FILENAME# = "array.txt"
DIM a$
a$("first") = 1
a$("second") = 2
a$("third") = 3
a$("fourth") = "Four"
a$("fourth", "temp") = "Temp"
FILEWRITE FILENAME#, a$
DIM b$ = FILEREAD(FILENAME#)
PRINT b$("fourth", "temp") ' Outputs: TempNotes: - Creates parent directories automatically if
they don’t exist - Completely replaces existing file contents - Silent
operation - no return value - Use \n for line breaks in
content - Escape backslashes in paths: "data\\save.txt" or
use forward slash: "data/save.txt"
FILEAPPEND filepath$, content$
Appends content to the end of an existing file, or creates the file if it doesn’t exist.
Syntax:
FILEAPPEND filepath$, content$Example:
LET timestamp$ = "2025-01-04 15:30:00"
LET logEntry$ = timestamp$ + " - Game started\n"
FILEAPPEND "gamelog.txt", logEntry$Notes: - Creates file if it doesn’t exist - Adds content to end without removing existing data - Perfect for logging and incremental data - Creates directories automatically if needed
FILEDELETE filepath$
Deletes a file from the file system.
Syntax:
FILEDELETE filepath$Example:
REM Clean up temporary files
IF FILEEXISTS("temp.dat") = 1 THEN
FILEDELETE "temp.dat"
PRINT "Temporary file removed"
ENDIFNotes: - Silent operation if file doesn’t exist - Irreversible operation - use with caution - Useful for cleanup and reset operations
FILELIST(array$, folder$ [, pattern$])
Fills an array with the names of the files in a folder and returns how many there are.
Syntax:
count$ = FILELIST(array$, folder$)
count$ = FILELIST(array$, folder$, pattern$)Example:
DIM files$
LET count$ = FILELIST(files$, PRG_ROOT# + "levels", "*.txt")
PRINT count$; " level files found"
FOR i$ = 0 TO count$ - 1
PRINT files$(i$)
NEXT i$
REM Load the first one - FILELIST gives names only, so add the folder back
IF count$ > 0 THEN
LET level$ = FILEREAD(PRG_ROOT# + "levels/" + files$(0))
ENDIFNotes: - Only files are listed, not folders.
Subfolders are not searched. - Returns file names only
(level1.txt), not full paths. - Names are sorted
alphabetically, ignoring case, and stored at keys 0 to
count - 1. - The array is emptied first, so calling
FILELIST again with the same array leaves no old names
behind. - pattern$ uses * (any characters) and
? (one character), e.g. "*.bas" or
"save?.dat". Without it, all files are listed. - Hidden and
system files are skipped. - If the folder doesn’t exist, returns
0 and the array is empty. - Relative folders are resolved
from the program’s folder, like the other file commands.
Loading key=value Files into Arrays (.env support)
When FILEREAD assigns to a DIM’d array,
BazzBasic automatically parses the file contents line by line into array
elements — using the key=value format that
.env files use.
DIM config$
LET config$ = FILEREAD("settings.txt")
PRINT config$("width") ' Output: 800
PRINT config$("height") ' Output: 600
PRINT config$("title") ' Output: My GameWhere settings.txt contains:
width=800
height=600
title=My Game
Lines beginning with # are treated as comments and
ignored:
# Game settings
width=800
height=600
# Display options
fullscreen=0
Using .env files for API keys
This makes standard .env files work directly for storing
sensitive values such as API keys outside of source code:
IF FILEEXISTS(".env") = 0 THEN
PRINT "Error: .env file not found"
END
END IF
DIM env$
LET env$ = FILEREAD(".env")
LET ApiKey# = env$("OPENAI_API_KEY")
LET OtherKey# = env$("OTHER_SERVICE_KEY")Where .env contains:
OPENAI_API_KEY=sk-proj-...
OTHER_SERVICE_KEY=abc123...
Important: Add .env to your
.gitignore to keep API keys out of version control:
.env
Note: This parsing only happens when assigning
FILEREAD to a DIM’d array. Assigning to a
regular variable (LET data$) always returns the raw file
contents as a plain string.
Path Handling
Relative vs Absolute Paths
Relative Paths (recommended for game files):
FILEWRITE "highscore.txt", "1000" REM Same directory as program
FILEWRITE "data/settings.txt", "sound=on" REM SubdirectoryAbsolute Paths (for system-wide access):
FILEWRITE "C:/Users/Player/Documents/save.txt", "data"Note: Use forward slashes / or escaped
backslashes \\ to avoid escape sequence issues:
REM CORRECT:
FILEWRITE "data/file.txt", "content"
FILEWRITE "data\\file.txt", "content"
REM WRONG (escape sequences):
FILEWRITE "data\file.txt", "content" REM \f becomes form feed!PRG_ROOT# Constant
BazzBasic provides a PRG_ROOT# constant containing the
program’s base directory path. It always ends with a directory
separator, so you can concatenate a relative path directly onto it
without adding your own / or \ first.
Example:
PRINT "Program root: "; PRG_ROOT#
REM Build absolute paths - no separator needed after PRG_ROOT#
LET savePath# = PRG_ROOT# + "saves/game1.txt"
FILEWRITE savePath#, "Player data"Use Cases: - Ensuring consistent file locations - Building absolute paths from relative ones - Debugging path issues
Complete Example: Highscore System
REM ============================================
REM Highscore Save/Load System
REM ============================================
CLS
PRINT "=== Highscore Demo ==="
PRINT ""
LET scoreFile$ = "highscore.txt"
LET currentScore$
REM Load existing highscore
IF FILEEXISTS(scoreFile$) = 1 THEN
LET scoreData$ = FILEREAD(scoreFile$)
LET highScore# = VAL(scoreData$)
PRINT "Current highscore: "; highScore$
ELSE
PRINT "No previous highscore found"
ENDIF
PRINT ""
PRINT "Play the game..."
REM Simulate gameplay
currentScore$ = RND(10000)
PRINT "Your score: "; currentScore$
PRINT ""
REM Check if new highscore
IF currentScore$ > highScore# THEN
PRINT "NEW HIGHSCORE!"
FILEWRITE scoreFile$, STR(currentScore$)
PRINT "Highscore saved!"
ELSE
PRINT "Better luck next time!"
ENDIF
ENDComplete Example: Game Settings
REM ============================================
REM Game Settings Manager
REM ============================================
LET settingsFile$ = "settings.txt"
LET soundEnabled$ = "1"
LET musicVolume$ = "80"
LET difficulty$ = "medium"
REM Load settings if they exist
IF FILEEXISTS(settingsFile$) = 1 THEN
PRINT "Loading settings..."
LET settings$ = FILEREAD(settingsFile$)
REM Parse settings (simple format: one per line)
REM In real game, you'd parse the string
PRINT "Settings loaded"
ELSE
PRINT "Creating default settings..."
REM Build settings string
LET settings$ = ""
settings$ = settings$ + "sound=" + soundEnabled$ + "\n"
settings$ = settings$ + "volume=" + musicVolume$ + "\n"
settings$ = settings$ + "difficulty=" + difficulty$ + "\n"
FILEWRITE settingsFile$, settings$
PRINT "Default settings saved"
ENDIF
REM Display settings
PRINT ""
PRINT "Current Settings:"
PRINT settings$
ENDComplete Example: Game Event Log
REM ============================================
REM Event Logging System
REM ============================================
LET logFile$ = "gamelog.txt"
REM Initialize log file
IF FILEEXISTS(logFile$) = 0 THEN
FILEWRITE logFile$, "=== Game Log ===\n"
ENDIF
REM Function to log an event
REM (In real code, use DEF FN)
LET event$ = "Game started"
FILEAPPEND logFile$, event$ + "\n"
REM Simulate game events
SLEEP 1000
event$ = "Player spawned at (100, 200)"
FILEAPPEND logFile$, event$ + "\n"
SLEEP 1000
event$ = "Enemy encountered"
FILEAPPEND logFile$, event$ + "\n"
SLEEP 1000
event$ = "Player health: 75"
FILEAPPEND logFile$, event$ + "\n"
SLEEP 1000
event$ = "Game ended"
FILEAPPEND logFile$, event$ + "\n"
PRINT "Events logged!"
PRINT ""
PRINT "Log contents:"
PRINT FILEREAD(logFile$)
ENDComplete Example: Save Game System
REM ============================================
REM Simple Save Game System
REM ============================================
LET saveFile$ = "savegame.dat"
REM Game state variables
LET playerName$ = "Hero"
LET playerLevel$ = 5
LET playerHealth$ = 85
LET playerGold$ = 1250
LET currentMap$ = "dungeon_2"
REM === SAVE GAME ===
PRINT "Saving game..."
REM Build save data string (simple format)
LET saveData$ = ""
saveData$ = saveData$ + playerName$ + "\n"
saveData$ = saveData$ + STR(playerLevel$) + "\n"
saveData$ = saveData$ + STR(playerHealth$) + "\n"
saveData$ = saveData$ + STR(playerGold$) + "\n"
saveData$ = saveData$ + currentMap$ + "\n"
FILEWRITE saveFile$, saveData$
PRINT "Game saved!"
PRINT ""
REM === LOAD GAME ===
PRINT "Loading game..."
IF FILEEXISTS(saveFile$) = 1 THEN
LET loadedData$ = FILEREAD(saveFile$)
PRINT "Save file loaded:"
PRINT loadedData$
REM In real game, parse the string and restore variables
PRINT "Game loaded successfully!"
ELSE
PRINT "No save file found!"
ENDIF
ENDTechnical Details
Automatic Directory Creation
- Parent directories are created automatically when writing files
- Example:
FILEWRITE "saves/slot1/data.txt", "..."createssaves/slot1/if needed - No need to manually create directory structure
Error Handling
- FILEREAD: Returns empty string on error (no exception)
- FILEEXISTS: Returns 0 on error or non-existent file
- FILEWRITE/FILEAPPEND/FILEDELETE: Silent failures (no exceptions)
- LOADJSON/LOADXML: A missing file stops the program — check with FILEEXISTS first (see Arrays & JSON)
- Check results with FILEEXISTS before/after operations if needed
Character Encoding
- Handles UTF-8 and other common text encodings automatically
- String content preserves line breaks and special characters
- Use
\nfor newlines,\tfor tabs in string literals
Path Resolution
- Relative paths: Resolved from program’s base
directory (PRG_ROOT#). This also applies to
LOADIMAGE,LOADSHEET,LOADSOUND,LOADFONTandSAVESCREEN - Absolute paths: Used as-is if rooted (e.g.,
C:/...) - Forward slashes
/work on all platforms - Backslashes must be escaped:
\\
Thread Safety
- All file operations are synchronous
- Safe for sequential access
- Avoid concurrent writes to same file
Best Practices
Check File Existence Before Reading
IF FILEEXISTS("data.txt") = TRUE THEN LET data$ = FILEREAD("data.txt") ELSE LET data$ = "" REM Default value ENDIFUse Relative Paths for Game Files
REM Keep game files organized FILEWRITE "saves/slot1.dat", saveData$ FILEWRITE "config/settings.txt", config$Structure Your Save Data
REM Use clear format (one value per line) LET data$ = "" data$ = data$ + "PlayerName=" + name$ + "\n" data$ = data$ + "Score=" + STR(score#) + "\n" FILEWRITE "save.txt", data$Use FILEAPPEND for Logs
REM Accumulate log entries FILEAPPEND "debug.log", "Error occurred\n"Clean Up Temporary Files
REM At program exit IF FILEEXISTS("temp.dat") = 1 THEN FILEDELETE "temp.dat" ENDIFEscape Path Separators
REM CORRECT: FILEWRITE "data/save.txt", content$ FILEWRITE "data\\save.txt", content$ REM WRONG: FILEWRITE "data\save.txt", content$ REM \s might be escape!
Common Patterns
Save/Load Pattern
REM Save
FILEWRITE "game.sav", gameState$
REM Load
IF FILEEXISTS("game.sav") = 1 THEN
gameState$ = FILEREAD("game.sav")
ENDIFConfig File Pattern
REM Load or create default
IF FILEEXISTS("config.txt") = 0 THEN
FILEWRITE "config.txt", defaultConfig$
ENDIF
config$ = FILEREAD("config.txt")Incremental Log Pattern
REM Add entries over time
FILEAPPEND "log.txt", timestamp$ + ": " + message$ + "\n"Multiple Save Slots
LET slot$ = 1
LET filename$ = "save" + STR(slot$) + ".dat"
FILEWRITE filename$, data$Troubleshooting
Problem: FILEREAD returns empty string - Check file exists with FILEEXISTS first - Verify file path is correct (use forward slashes) - Check file isn’t locked by another program - Try absolute path to debug
Problem: FILEWRITE doesn’t create file - Check path doesn’t contain invalid characters - Verify disk isn’t full or write-protected - Check permissions on target directory
Problem: Escape sequence in path - Use forward
slashes: "data/file.txt" - Or escape backslashes:
"data\\file.txt" - Avoid: \n, \t,
\r in paths
Problem: Can’t find files after writing - Print
PRG_ROOT# to see base directory - Use absolute paths for debugging -
Asset and file paths follow PRG_ROOT# (the program’s
folder), not the folder you launched the program from
Limitations
- Text files only (no binary data support)
- No file size limits enforced (use caution with large files)
- No file locking or concurrent access control
- No file metadata (size, dates, permissions)
- No copy or move operations
Future Enhancements
Potential additions to the file system:
- Binary file support (read/write bytes)
- File copy and move operations
- File metadata queries (size, modified date)
- File locking for concurrent access
- Stream-based reading for large files
- CSV parsing helpers (JSON is already supported, see Arrays & JSON)
- Compression support
Screen Control
SCREEN - Initialize Graphics Mode
Initialize SDL2 graphics window with specified resolution and title.
SCREEN mode ' Standard BASIC mode
SCREEN 0, width, height ' Custom resolution
SCREEN 0, width, height, "Title" ' Custom resolution with window titleStandard BASIC Modes
| Mode | Resolution | Description |
|---|---|---|
| 0 | 640×400 | Text emulation mode |
| 1 | 320×200 | Low resolution |
| 2 | 640×350 | Medium resolution |
| 7 | 320×200 | VGA low-res |
| 9 | 640×350 | EGA enhanced |
| 12 | 640×480 | VGA standard (recommended) |
| 13 | 320×200 | MCGA mode |
Examples
SCREEN 12 ' 640×480 VGA mode
SCREEN 0, 800, 600 ' 800×600 custom size
SCREEN 0, 1024, 768, "My Game" ' 1024×768 with custom titleCLS
Clear entire screen to background color.
Note: See performance tips for graphics
CLS ' Clear screen
COLOR 0, 1 ' Set blue background
CLS ' Clear to blueFULLSCREEN
Toggle fullscreen mode (borderless window). Note: Fullscreen is only supported in graphics modes (not console mode).
SCREEN 0, 640, 480, "My title"
FULLSCREEN TRUE ' borderless fullscreen on
' ...
FULLSCREEN FALSE ' Windowed modeLOCATE
Move text cursor to specified row and column (1-based).
LOCATE row, column
LOCATE 10, 20 ' Row 10, Column 20
PRINT "Centered"
LOCATE 1, 1 ' Top-left corner
PRINT "Header"Note: - In graphics mode, character positions are based on 8×8 pixel font cells. - While PRINT works, it is recommended to use DRAWSTRING since PRINT can make graphic screen to blink if FPS rate is high.
COLOR
Set foreground (text) and background colors. Accepts palette indices
0–15 only — for full RGB on graphics primitives, use RGB()
or a built-in color constant like RED# with
LINE, CIRCLE, etc. instead.
COLOR foreground, background
COLOR 14, 1 ' Yellow text on blue background
PRINT "Warning!"
COLOR 15, 0 ' White on black (default)Color Palette (0-15)
| Value | Color | Value | Color |
|---|---|---|---|
| 0 | Black | 8 | Dark Gray |
| 1 | Blue | 9 | Light Blue |
| 2 | Green | 10 | Light Green |
| 3 | Cyan | 11 | Light Cyan |
| 4 | Red | 12 | Light Red |
| 5 | Magenta | 13 | Light Magenta |
| 6 | Brown | 14 | Yellow |
| 7 | Light Gray | 15 | White |
SCREENLOCK
Control when graphics are displayed to prevent flickering.
SCREENLOCK ON ' Lock screen (start buffering)
SCREENLOCK OFF ' Unlock and display (present buffer)
SCREENLOCK ' Same as SCREENLOCK ONWhy use SCREENLOCK? Without screen locking, each graphics command immediately updates the display, causing visible flickering during animation. SCREENLOCK buffers all drawing commands and displays them at once.
Example - Smooth Animation
[inits]
' declarations and initialisations before loops etc.
LET angle$ = 0
SCREEN 12
[main]
WHILE INKEY <> 27
' keep logic and math out of SCREENLOCK ON/OFF
angle$ = angle$ + 5
' Start buffering. Indents helps with SCREENLOCK ON/OFF
SCREENLOCK ON
' clear with LINE...BF
LINE (0, 0)-(640, 480), 0, BF
' Draw multiple shapes
LINE (100,100)-(200,200), 15
CIRCLE (320, 240), 50, 12
SCREENLOCK OFF ' Display all at once
SLEEP 16 ' ~60 FPS
WEND
ENDVSYNC
Control vertical synchronization (VSync) to limit or maximize frame rate.
VSYNC(TRUE) ' Enable VSync (default)
VSYNC(FALSE) ' Disable VSyncParameters: - TRUE or any non-zero
value - Enable VSync - FALSE or 0 - Disable
VSync
What is VSync?
VSync synchronizes frame rendering with your monitor’s refresh rate (typically 60Hz = 60 FPS). This prevents screen tearing (horizontal lines during fast motion) but limits maximum frame rate.
When to use: - VSYNC(TRUE) - Normal
gameplay (smoother, no tearing) - VSYNC(FALSE) -
Benchmarking, performance testing, FPS measurement
Important: - VSync is enabled by
default when you call SCREEN - Call
VSYNC after the SCREEN
command - If rendering takes longer than 16.67ms (1/60s), VSync will
lock to 30 FPS instead of 60 FPS
Performance Impact
' With VSync enabled (default):
' - FPS capped at monitor refresh rate (usually 60)
' - Smooth rendering, no screen tearing
' - If frame takes > 16.67ms → drops to 30 FPS
' With VSync disabled:
' - Unlimited FPS (can exceed 100+ FPS)
' - May show screen tearing
' - Better for performance benchmarkingExample - FPS Testing
' BazzBasic version 1.3
' https://ekbass.github.io/BazzBasic/
[inits]
LET frameCount$ = 0
LET lastTime$ = TICKS
LET frameCount$ = 0
LET currentTime$ = 0
LET fps$
SCREEN 12
VSYNC(FALSE) ' Disable for true FPS measurement
LET MY_COLOR# = RGB(255, 255, 255)
[main]
WHILE INKEY <> KEY_ESC#
' Calculate FPS
frameCount$ = frameCount$ + 1
currentTime$ = TICKS
IF currentTime$ - lastTime$ >= 1000 THEN
fps$ = frameCount$ / ((currentTime$ - lastTime$) / 1000)
frameCount$ = 0
lastTime$ = currentTime$
ENDIF
SCREENLOCK ON
' clear
LINE (0, 0)-(640, 480), 0, BF
' filled circle
CIRCLE (320, 240), 50, 12, 1
' fps
DRAWSTRING "FPS: " + STR(INT(fps$)), 0, 0, MY_COLOR#
SCREENLOCK OFF
WEND
VSYNC(TRUE) ' Restore default before exit
ENDExample - Toggle VSync at Runtime
' BazzBasic version 1.3
' https://ekbass.github.io/BazzBasic/
[inits]
SCREEN 12
LET vSyncStatus$ = TRUE
VSYNC(vSyncStatus$)
LET vColor$ = RGB(255, 255, 255)
LET vString$
LET key$
LET running$ = TRUE
[main]
WHILE running$
IF KEYDOWN(KEY_ESC#) THEN running$ = FALSE
IF KEYDOWN(KEY_SPACE#) THEN
vSyncStatus$ = NOT vSyncStatus$
VSYNC(vSyncStatus$)
' Wait until space is released or it gets buffered and in problems
WHILE KEYDOWN(KEY_SPACE#) : WEND
IF vSyncStatus$ = TRUE THEN
vString$ = "VSync: ON "
ELSE
vString$ = "VSync: OFF "
END IF
END IF
SCREENLOCK ON
LINE (0,0)-(639,479), 0, BF
DRAWSTRING vString$, 0, 16, vColor$
SCREENLOCK OFF
SLEEP 16
WEND
ENDTroubleshooting:
If your game runs at 30 FPS instead of 60 FPS with VSync enabled: 1.
Your rendering takes > 16.67ms per frame 2. VSync forces wait for
next refresh (60 FPS ÷ 2 = 30 FPS) 3. Solutions: - Reduce number of rays
in raycaster - Lower screen resolution - Optimize rendering code - Use
VSYNC(FALSE) to test maximum achievable FPS
Basic Graphics Primitives
About color parameters
Every drawing command in this section (PSET,
LINE, CIRCLE, PAINT,
DRAWSTRING, LOADSHAPE) accepts a
color parameter that can be either:
- A palette index 0–15 — the classic 16-color EGA/VGA
palette (
0= black,15= white, etc.) - An
RGB(r, g, b)value — any of the 16 million colors, each channel0–255 - A built-in color constant —
BLACK#…TRANSPARENT#are 32-bit ARGB values (since 1.8), e.g.RED#= 0xFFFF0000 = RGB(255, 0, 0)
You can mix and match freely:
PSET (100, 100), 12 ' Palette index 12 = light red
PSET (100, 100), RGB(255, 64, 0) ' Custom orange-red
PSET (100, 100), RED# ' Built-in constant (since 1.8)The COLOR text-mode command is the exception — it only
accepts palette indices 0–15.
PSET - Draw Pixel
Draw a single pixel at coordinates (x, y).
PSET (x, y), color
PSET (100, 100), 15 ' White pixel
PSET (320, 240), 12 ' Red pixel at centerLINE - Draw Lines and Boxes
Draw lines or filled/unfilled rectangles.
LINE (x1, y1)-(x2, y2), color ' Line
LINE (x1, y1)-(x2, y2), color, B ' Box (outline)
LINE (x1, y1)-(x2, y2), color, BF ' Box FilledBoth corners are inclusive in all three forms:
(x2, y2) is drawn as part of the line or box.
LINE (10, 10)-(12, 12), c, BF fills a 3×3 area. Corners can
be given in any order. To cover a 640×480 screen exactly, use
LINE (0, 0)-(639, 479), 0, BF — coordinates outside the
window are clipped, so (640, 480) also works.
Examples
LINE (10, 10)-(100, 50), 15 ' White line
LINE (50, 50)-(150, 150), 12, B ' Red box outline
LINE (200, 100)-(300, 200), 9, BF ' Blue filled boxCIRCLE - Draw Circle
Draw circle or filled circle at center point.
CIRCLE (centerX, centerY), radius, color
CIRCLE (centerX, centerY), radius, color, filled
CIRCLE (320, 240), 50, 14 ' Yellow circle outline
CIRCLE (100, 100), 30, 12, 1 ' Red filled circlePAINT - Fill Area
Flood-fill starting at (x, y), like in QB/FreeBASIC: the contiguous
area of the starting pixel’s color is painted with
fillColor, stopping at pixels of borderColor.
The border color is optional — without it the fill color is used as the
border, so the fill stops at any pixel already in the fill color.
PAINT (x, y), fillColor[, borderColor]
' Draw and fill a box
LINE (100, 100)-(200, 200), 15, B ' White border
PAINT (150, 150), 12, 15 ' Fill red inside the white border
PAINT (300, 150), 10 ' Fill green; border = fill color (10)RGB - Create Color Value
Create custom RGB color (0-255 per channel). The returned value can
be used with any drawing command (PSET, LINE,
CIRCLE, PAINT, DRAWSTRING,
LOADSHAPE) in place of a palette index.
LET color$ = RGB(red, green, blue)
LET purple$ = RGB(128, 0, 128)
PSET (100, 100), purple$
LET orange$ = RGB(255, 165, 0)
CIRCLE (320, 240), 50, orange$POINT - Read pixel color from screen
Returns a RGP color value from certain point of the screen.
LET c$ = POINT(100, 100)SAVESCREEN - Save the screen as PNG
Saves everything drawn on the graphics screen to a PNG file.
SCREEN 0, 320, 200
CIRCLE (160, 100), 50, RGB(255, 0, 0), 1
SAVESCREEN "circle.png"- Relative paths resolve against the program’s folder (same as
PRG_ROOT#). The folder must already exist. - Only
.pngis supported; any other extension is an error. - An existing file with the same name is overwritten.
- The image has the program’s screen size (as set with
SCREEN), also in fullscreen. It is always fully opaque. - It saves what has been drawn, including drawing done after
SCREENLOCK ONthat has not been shown yet. - Requires graphics mode: without
SCREEN, it stops withSAVESCREEN: graphics mode not initialized. Use SCREEN first.
Handy for screenshots, saving generated art, and checking the output of drawing programs (e.g. Rosetta Code tasks) without looking at the window.
DRAWSTRING & LOADFONT
Render text directly to the SDL2 graphics surface. Requires
SDL2_ttf.dll in the same directory as the interpreter.
' Default font (Arial, size 16)
DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
' Load alternative font — becomes the new active font
LOADFONT "myfont.ttf", 24
DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
' Reset to default (Arial, size 16)
LOADFONT
DRAWSTRING positions text by its top-left
corner. Prefer it over PRINT in graphics mode —
PRINT bypasses the SDL2 rendering pipeline and causes
flickering at higher frame rates.
Fonts
SDL2_ttf loads any standard .ttf or .otf
font file. BazzBasic defaults to Arial (size 16). To
use a different font, call LOADFONT with a font filename
and point size. The loaded font stays active until you call
LOADFONT again or reset it.
Bundling fonts with your program (recommended)
Copy the .ttf file into the same folder as your
.bas file and reference it by filename:
LOADFONT "PressStart2P.ttf", 16
DRAWSTRING "GAME OVER", 200, 200, RGB(255, 0, 0)
This makes your program portable and not dependent on the fonts installed on the user’s system. Free fonts are widely available — Google Fonts offers hundreds under the OFL open-source licence.
Using Windows system fonts
You can also reference fonts already installed on Windows by full path:
LOADFONT "C:\\Windows\\Fonts\\consola.ttf", 14 ' Consolas (monospace)
LOADFONT "C:\\Windows\\Fonts\\times.ttf", 18 ' Times New Roman
Note: this works only on Windows and only if the font is installed — not recommended for distributed programs.
Font sizes
The size parameter is a point size — any positive integer is valid:
| Use | Size |
|---|---|
| Small UI / HUD text | 12–14 |
| Normal text | 16–20 |
| Subheadings | 24–32 |
| Titles / headings | 48–64 |
| Splash screens | 72–96 |
Shape System (Sprites)
LOADSHAPE - Create Shape
Create or load a new shape and return its ID.
id$ = LOADSHAPE(type$, width, height, color)Shape types: - "RECTANGLE" - Rectangle
shape - "CIRCLE" - Circle shape
- "TRIANGLE" - Triangle shape
Examples
LET SQUARE# = LOADSHAPE("RECTANGLE", 50, 50, RGB(255, 0, 0))
LET BALL# = LOADSHAPE("CIRCLE", 40, 40, RGB(0, 255, 0))
LET ARROW# = LOADSHAPE("TRIANGLE", 30, 40, RGB(0, 0, 255))LOADSHEET - Load Sprite Sheet
Reads an image file and splits it into sprites according to the specification. The original image size must be divisible by the given size parameters
- Relative paths resolve against the program’s folder (same as
PRG_ROOT#), e.g."assets/sheet.png"works no matter where you launch from. Absolute paths are used as-is. - A missing or unloadable file halts the program with an
Error at line N: ...message (File not found: <path>), exit code 1.
' BazzBasic version 1.3
' https://ekbass.github.io/BazzBasic/
' ============================================
' LOADSHEET demo: countdown 9 -> 0
' sheet_numbers.png: 640x256, 128x128 sprites
' ============================================
[inits]
' Center position for a 128x128 sprite on 640x480 screen
LET x# = 256
LET y# = 176
DIM sprites$
SCREEN 0, 640, 480, "Countdown!"
LOADSHEET sprites$, 128, 128, "Examples/images/sheet_numbers.png"
[main]
' Count down from 9 to 0
FOR i$ = ROWCOUNT(sprites$()) - 1 TO 0 STEP -1
SCREENLOCK ON
LINE (0, 0)-(640, 480), 0, BF
MOVESHAPE sprites$(i$), x#, y#
DRAWSHAPE sprites$(i$)
SCREENLOCK OFF
SLEEP 500
NEXT
ENDMOVESHAPE - Position Shape
Move shape to absolute screen position.
MOVESHAPE ID#, x, yAnchor point depends on shape type: -
LOADSHAPE primitives (RECTANGLE,
CIRCLE, TRIANGLE) are positioned by their
center point — x, y is the middle of the
shape. - LOADIMAGE images are positioned by their
top-left point — see Image Transformations below.
ROTATESHAPE - Rotate Shape
Rotate shape to specified angle in degrees.
ROTATESHAPE id$, angle
ROTATESHAPE SQUARE#, 45 ' 45 degrees
ROTATESHAPE ARROW#, 180 ' Upside down
ROTATESHAPE ARROW#, 270 ' 90 degrees counter-clockwiseNote: Rotation is absolute, not cumulative. To spin continuously:
DIM angle$
LET angle$ = 0
WHILE 1
angle$ = angle$ + 5
IF angle$ >= 360 THEN
angle$ = 0
ENDIF
ROTATESHAPE SQUARE#, angle$
SLEEP 16
WENDSCALESHAPE - Scale Shape Size
Scale shape by multiplier (1.0 = original size).
SCALESHAPE id$, scale
SCALESHAPE BALL#, 0.5 ' Half size
SCALESHAPE SQUARE#, 2.0 ' Double size
SCALESHAPE ARROW#, 1.5 ' 150% sizePulsing effect:
DIM scale$
DIM direction$
LET scale$ = 1
LET direction$ = 0.01
WHILE 1
scale$ = scale$ + direction$
IF scale$ >= 1.5 OR scale$ <= 0.5 THEN
direction$ = direction$ * -1
ENDIF
SCALESHAPE BALL#, scale$
SLEEP 16
WENDDRAWSHAPE - Render Shape
Draw shape to screen at current position/rotation/scale.
DRAWSHAPE SQUARE#
SCREENLOCK ON
LINE (0, 0)-(640, 480), 0, BF
DRAWSHAPE SQUARE#
DRAWSHAPE BALL#
DRAWSHAPE ARROW#
SCREENLOCK OFFImportant: Use with SCREENLOCK for smooth rendering!
SHOWSHAPE / HIDESHAPE - Toggle Visibility
Show or hide shape without removing it.
SHOWSHAPE id$
HIDESHAPE id$
HIDESHAPE ENEMY# ' Temporarily hide
' ... do something ...
SHOWSHAPE ENEMY# ' Show againREMOVESHAPE - Delete Shape
Permanently remove shape from memory.
REMOVESHAPE ID#
REMOVESHAPE SQUARE# ' Delete and free memoryNote: Always remove shapes when done to free memory!
LOADIMAGE
Note: Images can be handled just as shapes
- Relative paths resolve against the program’s folder (same as
PRG_ROOT#), e.g."assets/plane.png"works no matter where you launch from. Absolute paths are used as-is.http(s)://URLs are also accepted (downloaded into the program’s folder first — see below). - A missing or unloadable file halts the program with
Error at line N: Failed to load image: File not found: <path>(exit code 1).
[inits]
SCREEN 12
LET SPRITE# = LOADIMAGE("temp.bmp")
MOVESHAPE SPRITE#, 320, 240
ROTATESHAPE SPRITE#, 45 ' Rotate 45
SCALESHAPE SPRITE#, 2.0 ' Scale by 2
[main]
SCREENLOCK ON
DRAWSHAPE SPRITE#
SCREENLOCK OFF
SLEEP 3000
REMOVESHAPE SPRITE# ' Free mem
ENDLOADIMAGE with url
LET SPRITE# = LOADIMAGE("https://example.com/sprite.png")
' → downloads "sprite.png" to root of your program
' → sprite$ works just as with normal file load
' to remove or move the downloaded file
SHELL("move sprite.png images\sprite.png") ' move to subfolder
' or
FILEDELETE "sprite.png" ' just delete itDrawing on Screen
Complete Examples
Example 1: Rotating Shapes
Example 2: Bouncing Ball
Performance Tips
Always use SCREENLOCK for animation:
WHILE 1 ' Math and logic here SCREENLOCK ON ' All drawing here SCREENLOCK OFF ' Delay here SLEEP 16 WENDClear only what you need:
' Clear only draw area, not text COLOR 0, 0 LINE (0, 50)-(640, 480), 0, BFLINE… BF is much faster than CLS
' Filling screen with LINE... BF is faster than CLS ' CLS works fine with console COLOR 0, 0 LINE (0, 80)-(640, 480), 0, BFRemove unused shapes:
REMOVESHAPE OLD_SHAPE# ' Free memoryUse RGB() once, store value:
LET MY_COLOR# = RGB(128, 64, 200) ' Use MY_COLOR# multiple timesTarget 60 FPS with SLEEP 16:
SLEEP 16 ' ~60 FPS (1000ms / 60 ≈ 16ms)
Image Support
LOADIMAGE Function
Load images as shapes that can be moved, rotated, and scaled.
Supported Formats
| Format | Transparency | Notes |
|---|---|---|
| PNG | Full alpha (0-255) | Recommended for sprites |
| BMP | None | Legacy support |
Usage
LET ID# = LOADIMAGE("filepath")Parameters: - filepath - Path to image
file (PNG or BMP)
Returns: - Shape ID string (use with MOVESHAPE, ROTATESHAPE, etc.)
Example
[inits]
SCREEN 12
REM Load PNG image with transparency
LET SPRITE# = LOADIMAGE("player.png")
REM Position and transform
MOVESHAPE SPRITE#, 320, 240
ROTATESHAPE SPRITE#, 45
SCALESHAPE SPRITE#, 2.0
[main]
REM Draw
SCREENLOCK ON
DRAWSHAPE SPRITE#
SCREENLOCK OFF
SLEEP 3000
REM Cleanup when done
REMOVESHAPE SPRITE#
ENDPNG Transparency (Alpha Channel)
PNG images support full alpha transparency. Each pixel can have an alpha value from 0 to 255:
| Alpha Value | Result |
|---|---|
| 255 | Fully opaque (solid) |
| 128 | 50% transparent |
| 0 | Fully transparent |
Transparency is read directly from the PNG file - no color key needed.
Image Transformations
Once loaded, images work exactly like other shapes:
LET IMG# = LOADIMAGE("logo.png")
MOVESHAPE IMG#, x, y ' Position (top-left point)
ROTATESHAPE IMG#, angle ' Rotate (degrees)
SCALESHAPE IMG#, scale ' Scale (1.0 = original size)
SHOWSHAPE IMG# ' Make visible
HIDESHAPE IMG# ' Make invisible
DRAWSHAPE IMG# ' Render to screen
REMOVESHAPE IMG# ' Delete and free memoryNotes
- Images are positioned by their top-left point
- PNG is recommended for all new projects
- Larger images use more memory
Why Constants, Not Variables?
IDs returned by LOADIMAGE are text handles (such as
SHAPE1). BazzBasic uses them only to point to the correct
image resource — they never change during program execution.
Storing them in constants (# suffix) communicates this
intent clearly:
LET PISTOL# = LOADIMAGE("pistol.png")
LET GAME_OVER# = LOADIMAGE("gameOver.png")
Using a mutable variable ($ suffix) would work, but it
implies the value could change — which is misleading and leaves
the door open for accidental reassignment bugs.
The rule of thumb: if a value is set once and never modified, it belongs in a constant.
When to Use an Array Instead
If your program loads many images at once, individual constants become verbose. In that case, a named array is cleaner and self-documenting:
DIM images$
images$("shoot") = LOADIMAGE("shoot.png")
images$("explosion") = LOADIMAGE("explosion.png")
images$("pickup") = LOADIMAGE("pickup.png")
For larger projects with categorized images, multidimensional string keys scale even better:
DIM images$
images$("weapons", "shotgun") = LOADIMAGE("shotgun.png")
images$("weapons", "ak47") = LOADIMAGE("ak47.png")
images$("explosions", "small") = LOADIMAGE("explosion_small.png")
images$("explosions", "large") = LOADIMAGE("explosion_large.png")
This keeps image assets organized by category and type — easy to extend without renaming anything.
Sound System
BazzBasic includes a comprehensive sound system built on SDL2_mixer, supporting audio playback with both background and blocking modes.
Overview
The sound system allows you to: - Load sound files in various formats (WAV, MP3, etc.) - Play sounds once or in a continuous loop - Control playback (stop individual sounds or all at once) - Choose between background playback or wait-for-completion modes
Supported Audio Formats
- WAV (recommended for best compatibility)
- MP3
- Other formats supported by SDL2_mixer.dll
Sound Commands
LOADSOUND(filepath$)
Loads a sound file from disk and returns a unique sound ID string.
Returns: String - Unique identifier for the loaded sound
Syntax:
LET SOUND_ID# = LOADSOUND("path/to/sound.wav")
' or
LET SOUND_ID# = LOADSOUND("path\\to\\sound.wav")Note: If you use “", you must use it as double”\” since it is also a escape character
Example:
LET EXPLOSION#
EXPLOSION# = LOADSOUND("C:\\sounds\\explosion.wav")
PRINT "Sound loaded with ID: "; EXPLOSION#Notes: - Relative paths resolve against the
program’s folder (same as PRG_ROOT#),
e.g. "sounds/jump.wav" works no matter where you launch
from. Absolute paths are used as-is. - The file must exist, or the
program halts with
Error at line N: LOADSOUND: Sound file not found: <path>
(exit code 1) - Each call to LOADSOUND creates a new independent sound
instance - The same file can be loaded multiple times for overlapping
playback
SOUNDONCE(SOUND_ID#)
Plays a loaded sound once in the background. Program execution continues immediately.
Syntax:
SOUNDONCE(SOUND_ID#)Example:
LET BEEP#
BEEP# = LOADSOUND("beep.wav")
SOUNDONCE(BEEP#)
PRINT "Sound playing in background..."
SLEEP 1000
PRINT "Continuing while sound plays..."Use Cases: - Sound effects in games - UI feedback sounds - Background audio that shouldn’t block program flow
SOUNDONCEWAIT(SOUND_ID#)
Plays a sound once and waits for playback to complete before continuing program execution.
Syntax:
SOUNDONCEWAIT(SOUND_ID#)Example:
LET INTRO#
INTRO# = LOADSOUND("intro_music.wav")
PRINT "Playing intro..."
SOUNDONCEWAIT(INTRO#)
PRINT "Intro finished, starting game!"Use Cases: - Intro music or narration - Sequential audio playback - When timing with program flow is critical
SOUNDREPEAT(SOUND_ID#)
Plays a sound in a continuous loop in the background.
Syntax:
SOUNDREPEAT(SOUND_ID#)Example:
LET BG_MUSIC#
BG_MUSIC# = LOADSOUND("background_music.wav")
SOUNDREPEAT(BG_MUSIC#)
PRINT "Music looping in background..."
REM Game loop runs hereNotes: - Sound loops seamlessly when it reaches the end - Use SOUNDSTOP to stop the loop - Multiple sounds can be looping simultaneously
Use Cases: - Background music - Ambient sounds (rain, wind, etc.) - Continuous sound effects
SOUNDSTOP(SOUND_ID#)
Stops playback of a specific sound.
Syntax:
SOUNDSTOP(SOUND_ID#)Example:
LET ALARM#
ALARM# = LOADSOUND("alarm.wav")
SOUNDREPEAT(ALARM#)
PRINT "Alarm ringing..."
SLEEP 5000
SOUNDSTOP(ALARM#)
PRINT "Alarm stopped"Notes: - Safe to call even if sound is not currently playing - Stops both looping and one-time playback
SOUNDSTOPALL
Stops all currently playing sounds at once.
Syntax:
SOUNDSTOPALLExample:
REM Emergency stop all audio
SOUNDSTOPALL
PRINT "All sounds stopped"Use Cases: - Game pause functionality - Switching between game states - Emergency audio cutoff - Cleanup before program exit
Complete Example: Game with Sound
REM ============================================
REM Simple Game with Sound Effects
REM ============================================
CLS
PRINT "Loading sounds..."
REM Load all game sounds
LET JUMP#, COIN#, DEATH#, BG_MUSIC#
JUMP# = LOADSOUND("C:\\game_sounds\\jump.wav")
COIN# = LOADSOUND("C:\\game_sounds\\coin.wav")
DEATH# = LOADSOUND("C:\\game_sounds\\death.wav")
BG_MUSIC# = LOADSOUND("C:\\game_sounds\\music.wav")
REM Start background music
SOUNDREPEAT(BG_MUSIC#)
REM Game variables
LET score$ = 0
LET playing$ = 1
LET coins_collected$ = 0
PRINT "Game started! Press SPACE to jump, ESC to quit"
REM Main game loop
WHILE playing$
LET key$ = INKEY
IF key$ = KEY_ESC# THEN
playing$ = 0
ENDIF
IF key$ = KEY_SPACE# THEN
SOUNDONCE(JUMP#)
PRINT "Jump!"
ENDIF
REM Simulate collecting a coin
IF RND(100) < 1 THEN
coins_collected$ = coins_collected$ + 1
score$ = score$ + 10
SOUNDONCE(COIN#)
PRINT "Coin collected! Score: "; score$
ENDIF
REM Simulate game over condition
IF coins_collected$ >= 10 THEN
playing$ = 0
ENDIF
SLEEP 50
WEND
REM Game over sequence
SOUNDSTOPALL
PRINT ""
PRINT "Game Over!"
PRINT "Final Score: "; score$
SOUNDONCEWAIT(DEATH#)
PRINT "Thanks for playing!"
ENDExample: Multiple Background Sounds
REM Layer multiple ambient sounds
LET RAIN#, WIND#, THUNDER#
RAIN# = LOADSOUND("rain.wav")
WIND# = LOADSOUND("wind.wav")
THUNDER# = LOADSOUND("thunder.wav")
REM Start ambient background
SOUNDREPEAT(RAIN#)
SOUNDREPEAT(WIND#)
PRINT "Storm ambience playing..."
SLEEP 5000
REM Add thunder effect
SOUNDONCE(THUNDER#)
SLEEP 3000
REM Stop all ambience
SOUNDSTOPALL
PRINT "Storm ended"
ENDExample: Sequential Audio Narration
REM Play audio files in sequence
LET PART1#, PART2#, PART3#
PART1# = LOADSOUND("narration_part1.wav")
PART2# = LOADSOUND("narration_part2.wav")
PART3# = LOADSOUND("narration_part3.wav")
PRINT "Starting narration..."
SOUNDONCEWAIT(PART1#)
PRINT "Part 1 complete"
SOUNDONCEWAIT(PART2#)
PRINT "Part 2 complete"
SOUNDONCEWAIT(PART3#)
PRINT "Narration finished!"
ENDTechnical Details
Thread Safety
- All sound operations are thread-safe
- Multiple sounds can play simultaneously
- Concurrent calls to SOUNDSTOP/SOUNDSTOPALL are handled safely
Memory Management
- Sound files are loaded into memory when LOADSOUND is called
- Each sound instance maintains its own playback state
- Resources are automatically cleaned up when program ends
- Use SOUNDSTOPALL before exit for clean shutdown
Performance Considerations
- Load sounds once at program start for best performance
- Avoid loading the same file repeatedly if possible
- Short sound effects are ideal for SOUNDONCE
- Longer audio files work well with SOUNDREPEAT
Looping Behavior
- SOUNDREPEAT loops seamlessly without gaps
- Loop restarts automatically when sound completes
- IsRepeating flag can be interrupted by SOUNDSTOP
Error Handling
- Invalid file paths throw exceptions with clear error messages
- Missing sound files are reported at load time
- Stopping non-existent sounds is a silent no-op
Best Practices
Organize Your Sounds
REM Load all sounds at startup LET SFX_JUMP#, SFX_COIN#, MUSIC_BG# SFX_JUMP# = LOADSOUND("sfx\\jump.wav") SFX_COIN# = LOADSOUND("sfx\\coin.wav") MUSIC_BG# = LOADSOUND("music\\background.wav")Use Appropriate Playback Modes
SOUNDONCE- Short sound effectsSOUNDREPEAT- Background music, ambient loopsSOUNDONCEWAIT- Sequential audio, narration
Clean Up Audio
REM Before program exit SOUNDSTOPALL ENDHandle Game States
REM When pausing game SOUNDSTOPALL REM When resuming SOUNDREPEAT(BG_MUSIC#)
Why Constants, Not Variables?
Sound IDs returned by LOADSOUND are text handles
(GUID-style, such as 57212810-1166-4bcf-8ccd-bdfc6607046f).
BazzBasic uses them only to point to the correct audio resource — they
never change during program execution.
Storing them in constants (# suffix) communicates this
intent clearly:
LET SHOOT_SND# = LOADSOUND("shoot.wav")
Using a mutable variable ($ suffix) would work, but it
implies the value could change — which is misleading and leaves
the door open for accidental reassignment bugs.
The rule of thumb: if a value is set once and never modified, it belongs in a constant.
When to Use an Array Instead
If your program loads many sounds at once, individual constants become verbose. In that case, a named array is cleaner and self-documenting:
DIM sounds$
sounds$("shoot") = LOADSOUND("shoot.wav")
sounds$("explosion") = LOADSOUND("explosion.wav")
sounds$("pickup") = LOADSOUND("pickup.wav")
SOUNDOCE(sounds$("shoot"))
For larger projects with categorized sounds, multidimensional string keys scale even better:
DIM sounds$
sounds$("shoot", "shotgun") = LOADSOUND("shoot_shotgun.wav")
sounds$("shoot", "ak47") = LOADSOUND("shoot_ak47.wav")
sounds$("explosion", "small") = LOADSOUND("explosion_small.wav")
sounds$("explosion", "large") = LOADSOUND("explosion_large.wav")
SOUNDONCE(sounds$("shoot", "ak47"))
This keeps sound assets organized by category and type — easy to extend without renaming anything.
Network
Note: httpbin.org is a good test address — it returns JSON showing what you sent. HTTPPOST sends Content-Type: application/json by default.
HTTPGET
Allows you to send HTTP GET requests to a specified URL and retrieve the response as a string.
LET response$ = HTTPGET("https://httpbin.org/get")
PRINT response$Output:
{
"args": {},
"headers": {
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-6999cff3-34d8f03c0661810224fe62db"
},
"origin": "84.231.65.52",
"url": "https://httpbin.org/get"
}
HTTPPOST
Allows you to send HTTP POST requests to a specified URL and retrieve the response as a string.
LET postResult$ = HTTPPOST("https://httpbin.org/post", "{""key"":""value""}")
PRINT postResult$Output;
{
"args": {},
"data": "{\"key\":\"value\"}",
"files": {},
"form": {},
"headers": {
"Content-Length": "15",
"Content-Type": "application/json; charset=utf-8",
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-6999d03a-3b47996d66ac7d8e65200a1e"
},
"json": {
"key": "value"
},
"origin": "84.231.65.52",
"url": "https://httpbin.org/post"
}
Optional parameters: headers and timeout
Both HTTPGET and HTTPPOST accept two
optional trailing arguments. The order is fixed — headers first, then
timeout:
HTTPGET(url$ [, headers$] [, timeout])
HTTPPOST(url$, body$ [, headers$] [, timeout])
headers$ is an array whose key/value pairs are sent as
request headers. timeout is the number of seconds to wait
for the response; the default is 30, and 0 (or less) means
no limit. Because timeout comes after headers, pass an empty array if
you want a custom timeout without sending any headers.
' Custom headers
DIM headers$
headers$("Authorization") = "Bearer mytoken"
LET res$ = HTTPGET("https://api.example.com/data", headers$)
' Longer timeout for a slow endpoint, e.g. a local LLM via Ollama.
' Note the empty headers array h$ so the timeout lands in the right slot.
DIM body$
body$("model") = "llama3.2" ' a model you have pulled in Ollama
body$("messages,0,role") = "user"
body$("messages,0,content") = "Say hi in three words."
DIM h$
LET raw$ = HTTPPOST("http://localhost:11434/v1/chat/completions", ASJSON(body$), h$, 120)
DIM result$
LET count$ = ASARRAY(result$, raw$)
PRINT result$("choices,0,message,content")If the timeout is exceeded, the call returns an empty string and
HTTPERROR holds a message such as
timed out after 120 s. See below.
HTTPERROR
Returns the error message of the latest HTTPGET or
HTTPPOST call, or an empty string if that call succeeded.
Parentheses are optional: HTTPERROR and
HTTPERROR() are the same.
A server that is down or unreachable is not a bug in your program, so
HTTPGET and HTTPPOST do not
stop the program when the request fails. They return an empty string and
store the reason in HTTPERROR. Your program decides what to
do next.
LET res$ = HTTPGET("https://example.com/feed")
IF HTTPERROR <> "" THEN
PRINT "Source is down: "; HTTPERROR
ELSE
PRINT res$
END IFEvery HTTPGET / HTTPPOST call resets
HTTPERROR, so read it right after the call you want to
check.
What counts as an error:
| Situation | Result |
|---|---|
Invalid URL (empty, or not http:// /
https://) |
Program stops with an error and line number — this is a mistake in your code |
| No connection, unknown host, connection dropped | Returns "", HTTPERROR holds the
reason |
| Timeout exceeded | Returns "", HTTPERROR =
timed out after N s |
| Server answers with an error status (404, 500…) | Not an error. Returns the server’s response body
(often an HTML error page), HTTPERROR is
"" |
Note: An empty result alone does not tell you that
something went wrong — a server can also answer successfully with an
empty body. Check HTTPERROR when the difference
matters.
HTTP Server (LISTEN)
BazzBasic can act as a small HTTP server to receive requests from a
browser-side HTML page, another program, or another computer. The
typical use is local glue: a static HTML page on the user’s machine
talks to BazzBasic via fetch().
By default the server is bound to 127.0.0.1 — only
programs on the same computer can reach it, and no admin rights are
needed on Windows. It can also listen on the network; see Listening on the network below.
Commands
| Command | Description |
|---|---|
STARTLISTEN port |
Open the given port on 127.0.0.1.
GETREQUEST() will block forever until a request
arrives. |
STARTLISTEN port, timeout_ms |
Same, but GETREQUEST() returns an empty string if no
request arrives within the timeout. 0 = wait forever. |
STARTLISTEN port, timeout_ms, host$ |
Listen on the given host instead of 127.0.0.1.
"*" = all network interfaces. See below. |
GETREQUEST() |
Block until a request arrives, then return the
POST/PUT/PATCH body or the GET query
string (without the leading ?). Returns
"" on timeout. |
SENDRESPONSE str$ |
Send 200 OK with the given body,
Content-Type: text/plain; charset=utf-8, and CORS headers.
Must be called after each GETREQUEST() so the browser does
not hang. |
STOPLISTEN |
Close the port. Silent no-op if no listener is active. |
Behaviour
- Only one listener can be active at a time. Calling
STARTLISTENwhile a listener is already open is an error — callSTOPLISTENfirst. OPTIONSpreflight requests sent by browsers for CORS are answered automatically with200 OK+ CORS headers and never reach user code. The script keeps waiting inGETREQUEST()for the real request.- If you call
GETREQUEST()again without first callingSENDRESPONSE, the previous request is automatically closed with an empty200 OKso the browser does not hang. This makes the API forgiving but you should still callSENDRESPONSEexplicitly. - All responses include
Access-Control-Allow-Origin: *, so an HTML page loaded withfile://or from a different port can post to your script without any extra setup.
Example: receive a JSON form post
STARTLISTEN 8080
PRINT "Listening on http://127.0.0.1:8080 ..."
LET json$ = GETREQUEST()
PRINT "Received: " + json$
' Parse the JSON into an array
DIM data$
LET count$ = ASARRAY(data$, json$)
PRINT "Name: " + data$("name")
SENDRESPONSE "{""status"":""ok""}"
STOPLISTEN
ENDMatching browser-side JavaScript:
fetch("http://127.0.0.1:8080", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "Krisu", level: 99 })
})
.then(r => r.json())
.then(data => console.log(data));Example: poll loop with timeout
STARTLISTEN 8080, 2000
LET running$ = 1
WHILE running$
LET req$ = GETREQUEST()
IF LEN(req$) = 0 THEN
PRINT "Idle..."
ELSE
PRINT "Got: " + req$
SENDRESPONSE "ok"
IF req$ = "quit" THEN
LET running$ = 0
END IF
END IF
WEND
STOPLISTEN
ENDListening on the network
Give a host as the third argument to accept connections from other computers:
STARTLISTEN 8080, 0, "*" ' all network interfaces, no timeout
STARTLISTEN 8080, 5000, "*" ' same, with a 5 s GETREQUEST timeout
STARTLISTEN 8080, 0, "192.168.1.10" ' one specific address"" (empty) means the default 127.0.0.1.
"*" means every network interface on this computer.
Windows needs a one-time permission. Listening on
anything other than 127.0.0.1 requires admin rights or a
URL reservation. Without it, STARTLISTEN stops with an
error that shows the exact command to run. Open a command prompt
as administrator and run it once, for example:
netsh http add urlacl url=http://+:8080/ user=Everyone
The reservation must match the port and host exactly. After that, the
program works without admin rights. To remove it later:
netsh http delete urlacl url=http://+:8080/
Things to know:
- Firewall. Windows Firewall usually asks the first time. If that question was dismissed earlier, the port stays closed and other computers simply cannot connect — there is no error in your program.
- A specific host is also a filter. With
"192.168.1.10", only requests addressed to exactly that name are accepted; a request tolocalhoston the same port is rejected. Use"*"if you want everything. - HTTP only. The server does not do HTTPS. For anything exposed to the internet, put a reverse proxy (e.g. Caddy, nginx) in front of it.
- Anyone who can reach the port can send requests.
There is no authentication and no size limit on the request body. Do not
open a port to the internet unless you know why, and check what
GETREQUEST()returns before acting on it.
Notes & limitations
- Only one request is handled at a time, sequentially. This is intentional — BazzBasic is single-threaded and aims for simple glue, not high-traffic web serving.
Access-Control-Allow-Origin: *means that any web page open in a browser on a computer that can reach the server can also send requests to it. This applies to127.0.0.1too.- The response is always
200 OKwithtext/plaincontent type. If you need to return JSON, just put JSON text in the body — browsers can still parse it withresponse.json(). Custom status codes are not supported in this version. GETrequests give you the query string (e.g.name=Krisu&age=50), not the URL path. Routing by path is not supported in this version.- For outgoing HTTP calls (calling other servers), see
HTTPGETandHTTPPOSTabove.
Preprocessor & Source Control
BazzBasic supports splitting your program across multiple files. This helps keep large programs organized and allows reusable code libraries.
INCLUDE
Include another BazzBasic source file. The contents of the included file are inserted at the exact point of the INCLUDE statement — as if you had written the code there directly.
INCLUDE "utils.bas"
INCLUDE "graphics_helpers.bas"
INCLUDE "MathLib.bb" ' Compiled libraryUsage Notes
- The path is relative to the file that has the INCLUDE line. If the file is not found there, BazzBasic looks in the main program’s folder
- Included files can contain functions, constants, or any valid BazzBasic code
- INCLUDE of the same
.basfile a second time does nothing: it is skipped with a warning, e.g.Warning: Line 2: Include 'helpers.bas' already included, skipping.The program still runs - Circular includes stop the program before it starts: A includes B
which includes A, or a file includes itself. The message is
Error: Circular INCLUDE detected: <file>
Example
main.bas:
INCLUDE "helpers.bas"
LET result$ = FN Square$(5)
PRINT result$ ' Output: 25helpers.bas:
DEF FN Square$(n$)
RETURN n$ * n$
END DEFBazzBasic reads these as a single program:
DEF FN Square$(n$)
RETURN n$ * n$
END DEF
LET result$ = FN Square$(5)
PRINT result$ ' Output: 25Errors in Included Files
Since 1.8, an error inside an included file names that file and the line in it.
main.bas:
INCLUDE "helpers.bas"
PRINT "Start"
PRINT FN Greet$("Anna")helpers.bas:
DEF FN Greet$(name$)
RETURN "Hello, " + nmae$
END DEFOutput:
Start
Error in helpers.bas line 2: Undefined variable: NMAE$
- The file name is shown as written in the INCLUDE line
- Errors found before the program starts have the form
Error: helpers.bas line 2: ... - Errors in the main program keep the usual form,
Error at line N: ...(orError: Line N: ...). N is the line in the main file; lines of included files are not counted
Compiled Libraries (.bb)
Library files contain only DEF FN functions and are
compiled to a tokenized .bb format.
' Compile: bazzbasic.exe -lib MathLib.bas → MathLib.bb
INCLUDE "MathLib.bb"
' Library functions are prefixed with FILENAME_
PRINT FN MATHLIB_Square$(5) ' Output: 25- Libraries can only contain
DEF FNfunctions - Functions are auto-prefixed with the filename:
MATHLIB_functionname$ - Library functions can read global constants (
#) from the main program .bbfiles are not tied to one release, but a library compiled with a newer BazzBasic may use commands an older interpreter does not have
Recommended Program Structure
For larger programs, split code into focused files and INCLUDE them:
' main.bas
INCLUDE "constants.bas"
INCLUDE "functions.bas"
INCLUDE "inits.bas"
[main]
GOSUB [sub:update]
GOSUB [sub:draw]
SLEEP 16
GOTO [main]
END
INCLUDE "subs.bas"See Also
BazzBasic Reserved Words
Complete list of all reserved keywords. All are
case-insensitive.
Variables must end with $, constants with # —
they cannot share names with keywords.
Control Flow
| Keyword | Description |
|---|---|
DEF |
Begin function definition (DEF FN name$(...)) |
DIM |
Declare array (re-DIM of an existing global array keeps its contents) |
ELSE |
Alternative branch in IF block |
ELSEIF |
Chained condition in IF block |
END |
Terminate program; also END IF,
END DEF |
ENDIF |
Close IF block (alias for END IF) |
EXIT |
Leave a loop early: EXIT WHILE,
EXIT FOR |
FN |
Call user-defined function (FN name$(...)) |
FOR |
Begin counted loop |
GOSUB |
Call subroutine at label |
GOTO |
Jump to label |
IF |
Conditional branch |
INCLUDE |
Insert source file or library |
LET |
Declare variable or constant |
NEXT |
End FOR loop |
PRINT |
Output to screen |
REM |
Comment (also ') |
RETURN |
Return from GOSUB or DEF FN |
STEP |
Loop increment in FOR |
THEN |
Required after IF condition |
TO |
Range separator in FOR |
WEND |
End WHILE loop |
WHILE |
Begin conditional loop |
I/O
| Keyword | Description |
|---|---|
ARGCOUNT |
Returns amount or args. passed to program |
ARGS |
Returns specific arg. passed to program |
CLS |
Clear screen |
COLOR |
Set text foreground/background color |
CURPOS |
Read cursor row or col: CURPOS("row") /
CURPOS("col") |
GETCONSOLE |
Read character or color from console position |
INPUT |
Read user input |
ISSET |
TRUE if a variable or constant exists (ISSET(name$));
array elements are always FALSE |
LINE INPUT |
Read full line including spaces |
LOCATE |
Move text cursor |
SLEEP |
Pause execution (milliseconds) |
Graphics
| Keyword | Description |
|---|---|
B |
Draw box outline instead of line
(LINE (x1,y1)-(x2,y2), color, B) |
BF |
Draw filled box instead of line
(LINE (x1,y1)-(x2,y2), color, BF) |
CIRCLE |
Draw circle or filled circle |
DRAWSHAPE |
Render a shape/image to screen |
DRAWSTRING |
Render a text to screen |
FULLSCREEN |
Toggle borderless fullscreen |
HIDESHAPE |
Hide shape without removing |
LINE |
Draw line, box outline, or filled box |
LOADFONT |
Load font from file or reset to Arial |
LOADIMAGE |
Load PNG/BMP (or URL) as shape |
LOADSHEET |
Load sprite sheet into array |
LOADSHAPE |
Create geometric shape |
MOVESHAPE |
Set shape position |
PAINT |
Flood fill |
POINT |
Read pixel color |
PSET |
Draw single pixel |
REMOVESHAPE |
Delete shape and free memory |
RGB |
Create color value from R, G, B components |
ROTATESHAPE |
Rotate shape (absolute degrees) |
SAVESCREEN |
Save the graphics screen as a PNG file |
SCALESHAPE |
Scale shape |
SCREEN |
Initialize graphics window |
SCREENLOCK |
Buffer drawing (ON) / present frame
(OFF) |
SHOWSHAPE |
Make hidden shape visible |
VSYNC |
Enable/disable vertical sync |
Sound
| Keyword | Description |
|---|---|
LOADSOUND |
Load sound file, returns ID |
SOUNDONCE |
Play sound once (non-blocking) |
SOUNDONCEWAIT |
Play sound once (blocking) |
SOUNDREPEAT |
Loop sound continuously |
SOUNDSTOP |
Stop specific sound |
SOUNDSTOPALL |
Stop all sounds |
File
| Keyword | Description |
|---|---|
FILEAPPEND |
Append string to file |
FILEDELETE |
Delete a file |
FILEEXISTS |
Returns 1 if file exists |
FILELIST |
Fill array with file names in a folder, return count:
FILELIST(arr$, path$ [, pattern$]);
*/? wildcards |
FILEREAD |
Read file as string or key=value array |
FILEWRITE |
Write string or array to file |
SHELL |
Run system command, returns output |
Network & Data
| Keyword | Description |
|---|---|
ASARRAY |
Parse JSON or XML string into array (format detected from the first character) |
ASJSON |
Convert array to JSON string |
ASXML |
Convert array to XML string |
BASE64DECODE |
Decode Base64 string |
BASE64ENCODE |
Encode string to Base64 |
GETREQUEST |
Wait for an HTTP request (blocks); returns POST/PUT/PATCH body or
GET query string without ?; "" on timeout |
HTTPERROR |
Error message of the latest HTTPGET/HTTPPOST; "" if it
succeeded |
HTTPGET |
HTTP GET request; returns "" and sets
HTTPERROR on failure |
HTTPPOST |
HTTP POST request; returns "" and sets
HTTPERROR on failure |
LOADJSON |
Load JSON file into array |
LOADXML |
Load XML file into array |
SAVEJSON |
Save array as JSON file |
SAVEXML |
Save array as XML file |
SENDRESPONSE |
Send text response to the pending request (200 OK, CORS enabled) |
SHA256 |
SHA256 hash (64-char hex) |
STARTLISTEN |
Start HTTP server:
STARTLISTEN port [, timeout_ms [, host$]] (default host
127.0.0.1, "*" = all interfaces) |
STOPLISTEN |
Stop the HTTP server (silent no-op if none active) |
Math Functions
| Keyword | Description |
|---|---|
ABS |
Absolute value |
ATAN |
Arc tangent |
ATAN2 |
Arc tangent of y/x: ATAN2(y, x) |
BETWEEN |
TRUE if value is within range |
CEIL |
Round up |
CINT |
Round to nearest integer |
CLAMP |
Constrain value to range |
COS |
Cosine (radians) |
DEG |
Radians to degrees |
DISTANCE |
2D or 3D Euclidean distance |
EULER# |
Euler’s number (e = 2.71828…) |
EXP |
e raised to power |
FASTCOS |
Fast cosine (degrees, lookup table) |
FASTRAD |
Fast degrees-to-radians |
FASTSIN |
Fast sine (degrees, lookup table) |
FASTTRIG |
Enable/disable fast trig lookup tables |
FLOOR |
Round down |
HPI# |
π/2 (90°) |
INBETWEEN |
TRUE only if strictly between bounds; unlike BETWEEN,
equal to a bound is FALSE |
INT |
Truncate toward zero |
LERP |
Linear interpolation |
LOG |
Natural logarithm |
MAX |
Higher of two values |
MIN |
Lower of two values |
MOD |
Remainder |
PI# |
π (3.14159…) |
POW |
Power |
QPI# |
π/4 (45°) |
RAD |
Degrees to radians |
RND |
Random integer 0 to n-1 |
ROUND |
Standard rounding |
SGN |
Sign (-1, 0, 1) |
SIN |
Sine (radians) |
SQR |
Square root |
TAN |
Tangent (radians) |
TAU# |
2π (360°) |
The plain names without # (PI,
HPI, QPI, TAU,
EULER, PHI, GRAV,
GRAV_E) still work and give the same values, but are
deprecated since 1.9 — use the # forms (see the Built-in
Constants table below).
String Functions
| Keyword | Description |
|---|---|
ASC |
Character to ASCII code |
CHR |
ASCII code to character |
FSTRING |
Format a template; {{-name-}} placeholders are replaced
with variable/constant values |
INSTR |
Find substring position |
INVERT |
Reverse string |
LCASE |
Convert to lowercase |
LEFT |
First n characters |
LEN |
String length (also array element count) |
LTRIM |
Strip leading whitespace |
MID |
Substring |
REPEAT |
Repeat string n times |
REPLACE |
Replace all occurrences |
RIGHT |
Last n characters |
RTRIM |
Strip trailing whitespace |
SAME |
Exact text compare, case-sensitive (1 or 0) |
SPLIT |
Split string into array |
SRAND |
Random alphanumeric string |
STR |
Number to string |
TRIM |
Strip leading and trailing whitespace |
UCASE |
Convert to uppercase |
VAL |
String to number |
Input & Mouse
| Keyword | Description |
|---|---|
INKEY |
Non-blocking key check |
KEYDOWN |
TRUE if key is held (graphics mode only) |
MOUSEMIDDLE |
1 if middle button pressed (graphics mode) |
MOUSEHIDE |
Hide mouse cursor (graphics mode) |
MOUSELEFT |
1 if left button pressed (graphics mode) |
MOUSERIGHT |
1 if right button pressed (graphics mode) |
MOUSESHOW |
Show mouse cursor (graphics mode) |
MOUSEWHEEL |
Wheel notches since the last call, + = up (graphics mode) |
MOUSEX |
Mouse cursor X position (graphics mode) |
MOUSEY |
Mouse cursor Y position (graphics mode) |
WAITKEY |
Block until key pressed |
Gamepad
Works in console and graphics mode. A pad that is not connected reads
as “nothing pressed” (FALSE / 0 / "") — no error is raised,
so games need no guard code.
| Keyword | Description |
|---|---|
GAMEPADS |
Number of connected pads (GAMEPADS()) |
PADAXIS |
Axis value: sticks -1..1, triggers 0..1
(PADAXIS(pad, PAD_LX#)) |
PADBUTTON |
1 if button is pressed (PADBUTTON(pad, PAD_A#)) |
PADNAME |
Controller name or "" (PADNAME(pad)) |
PADRUMBLE |
Rumble the pad: PADRUMBLE pad, strength, ms
(parentheses optional) |
Arrays
| Keyword | Description |
|---|---|
ARRKEY |
Key at 0-based index in insertion order:
ARRKEY(arr$(), i); pairs with LEN(arr$()) for
loops |
DELARRAY |
Remove entire array |
DELKEY |
Remove one array element |
HASKEY |
1 if array element exists |
JOIN |
Merge two arrays; src2$ overwrites src1$ on conflict |
ROWCOUNT |
Return the size of array in first dimension |
Time
| Keyword | Description |
|---|---|
TICKS |
Milliseconds since program start |
TIME |
Current date/time as formatted string |
Logic
| Keyword | Description |
|---|---|
AND |
Logical AND |
FALSE |
0 |
NOT |
Logical NOT |
OFF |
Alias for FALSE (used with SCREENLOCK, VSYNC) |
ON |
Alias for TRUE (used with SCREENLOCK, VSYNC) |
OR |
Logical OR |
TRUE |
1 |
Built-in Constants
These are auto-initialized at startup — no LET
required.
| Constant | Value |
|---|---|
BBVER# |
BazzBasic version string (e.g. "1.1d") |
BBBUILD# |
Interpreter build time, "dd-mm-yyyy hh:mm:ss" |
PRG_ROOT# |
Program base directory path (ends with a directory separator) |
TRUE |
1 |
FALSE |
0 |
PI# |
3.141592653589793 |
HPI# |
1.5707963267948966 (π/2) |
QPI# |
0.7853981633974483 (π/4) |
TAU# |
6.283185307179586 (2π) |
EULER# |
2.718281828459045 (e) |
AU# |
149597870700 (astronomical unit in metres, exact — IAU 2012) |
PHI# |
1.618033988749895 (golden ratio) |
GRAV# |
6.6743E-11 (gravitational constant, m^3 kg^-1 s^-2) |
GRAV_E# |
9.80665 (standard gravity on Earth, m/s^2) |
BLACK# |
0xFF000000 (0, 0, 0) |
WHITE# |
0xFFFFFFFF (255, 255, 255) |
RED# |
0xFFFF0000 (255, 0, 0) |
GREEN# |
0xFF00FF00 (0, 255, 0) |
BLUE# |
0xFF0000FF (0, 0, 255) |
YELLOW# |
0xFFFFFF00 (255, 255, 0) |
CYAN# |
0xFF00FFFF (0, 255, 255) |
MAGENTA# |
0xFFFF00FF (255, 0, 255) |
GRAY# |
0xFF808080 (128, 128, 128) |
ORANGE# |
0xFFFFA500 (255, 165, 0) |
TRANSPARENT# |
0x00000000 (0, 0, 0, alpha 0) |
Keyboard constants
KEY_UP# KEY_DOWN# KEY_LEFT#
KEY_RIGHT#
KEY_ESC# KEY_ENTER# KEY_SPACE#
KEY_TAB# KEY_BACKSPACE#
KEY_INSERT# KEY_DELETE# KEY_HOME#
KEY_END# KEY_PGUP#
KEY_PGDN#
KEY_F1# … KEY_F12#
KEY_A# … KEY_Z#
KEY_0# … KEY_9#
KEY_NUMPAD0# … KEY_NUMPAD9#
KEY_NUMPAD_PLUS# KEY_NUMPAD_MINUS#
KEY_NUMPAD_MUL# KEY_NUMPAD_DIV#
KEY_NUMPAD_DOT#
KEY_LSHIFT# KEY_RSHIFT#
KEY_LCTRL# KEY_RCTRL# KEY_LALT#
KEY_RALT# KEY_LWIN#
KEY_RWIN#
KEY_COMMA# KEY_DOT# KEY_MINUS#
KEY_EQUALS# KEY_SLASH#
KEY_BACKSLASH# KEY_GRAVE#
KEY_LBRACKET# KEY_RBRACKET#
KEY_SEP#
Gamepad constants
Buttons (use with PADBUTTON(pad, PAD_A#)):
PAD_A# PAD_B# PAD_X#
PAD_Y# PAD_BACK# PAD_GUIDE#
PAD_START#
PAD_LSTICK# PAD_RSTICK# PAD_LB#
PAD_RB# PAD_UP# PAD_DOWN#
PAD_LEFT# PAD_RIGHT# PAD_MISC#
PAD_TOUCHPAD#
Axes (use with PADAXIS(pad, PAD_LX#)):
PAD_LX# PAD_LY# PAD_RX#
PAD_RY# PAD_LT# PAD_RT#
Button labels follow the Xbox layout; on PlayStation: A=Cross, B=Circle, X=Square, Y=Triangle.
Command Line
Switches for BazzBasic.exe itself — not language
keywords.
| Switch | Description |
|---|---|
-exe |
Compile a program to a standalone .exe:
BazzBasic.exe -exe program.bas |
-lib |
Compile a library to .bb:
BazzBasic.exe -lib library.bas |
-v |
Show version |
-version |
Show version (alias of -v) |