Byte Documentation
Reference & guide for the Byte browser-native scripting language (2026 edition)
Lightweight • Promise-based • Sandboxed • Canvas + Audio ready
1. Interpreter Pipeline
Byte is not a classic interpreter. It compiles each line into async-friendly JavaScript promises and executes them sequentially using await.
1.1 Parsing Stages
- Pre-processing — strip leading/trailing whitespace, remove
//comments - Line splitting — command (first word) vs payload (everything after)
- Block detection — lines ending in
=open scope; lone-closes it - Expression wrapping — anything inside
()is evaluated via safeFunctionsandbox
Important: Every opened block
= must have a matching -. Mismatched blocks are the #1 source of silent failures.
1.2 Safe Expression Evaluation
Expressions are evaluated in an isolated context:
new Function('ctx', 'with(ctx) { return ' + expr + ' }')(vars)
This gives safe access to math, variables, and library functions — but no window, document, eval, etc.
2. Core Keywords
| Keyword | Purpose | Arguments / Example | Notes |
|---|---|---|---|
| VAR | Mutable variable | VAR name value | Dynamic type |
| const | Immutable variable | const PI 3.14159 | Local scope only |
| RRI | Print to output | RRI "Hello" or RRI (score) | Appends to #runtime-out |
| WIT | Delay (ms) | WIT 500 | await new Promise(r ⇒ setTimeout(r, ms)) |
| EXE | Call named function/block | EXE update | From this.functions |
| EXTRACT | Load library | EXTRACT math | Merges into scope |
| STO | Stop script | STO | Clears buffers & exits |
| INPUT | User prompt | VAR name INPUT "Your name?" | Uses window.prompt |
| SET | Re-assign variable | SET score (score + 1) | More explicit than name = … |
| ALIAS | Create shortcut name | ALIAS print RRI | Useful for readability |
3. Control Flow & Loops
3.1 Conditionals
IF (score > 100) THN
RRI "Rank: S"
SET rank "S"
THN ELSE
RRI "Rank: A or lower"
END
3.2 While loops
VAR i 0
WHILE (i < 10) =
RRI (i)
SET i (i + 1)
-
3.3 For-style counted loops (most common pattern)
- 6 = // repeat 6 times
music.note "C4" 0.08 0.7
WIT 120
-
3.4 Early exit
IF (health <= 0) THN
RRI "GAME OVER"
STO
END
Safety limit: Loops are automatically terminated after ~120,000 iterations to prevent freezing the tab.
4. Standard Library Overview
4.1 math
abs(n), floor(n), ceil(n), round(n)
sqrt(n), pow(b,e), exp(n), log(n)
sin(r), cos(r), tan(r), atan2(y,x)
random(), randomInt(min,max)
clamp(v,lo,hi), lerp(a,b,t), map(v, a1,a2, b1,b2)
4.2 music (Web Audio API based)
wave("sine"|"square"|"sawtooth"|"triangle")
note("C#4", duration_sec, velocity 0–1)
chord(["C4","E4","G4"], 0.6, 0.8)
rest(seconds)
stopAll(), setBPM(n)
4.3 canvas (2D context helpers)
create(id, width, height) → returns context
fillRect(ctx, x,y,w,h, "#ff0044")
strokeRect(ctx, x,y,w,h, color, lineWidth)
circle(ctx, x,y,r, color, fill=true)
line(ctx, x1,y1,x2,y2, color, width)
text(ctx, str, x,y, color, size_px, font?)
clear(ctx), save(ctx), restore(ctx)
4.4 storage (localStorage wrapper)
storage.set("highscore", 42000)storage.get("highscore")→ number/string/objectstorage.has("key")→ booleanstorage.remove("key")storage.clear()
4.5 dom (basic DOM helpers – optional)
dom.setText("#score", score)dom.addClass("#player", "hurt")dom.hide / dom.show(selector)
5. Global Input & Event Hooks
Byte supports simple declarative event bindings:
// Keyboard (key = keyName EXE functionName)
key = " " EXE playerJump
key = "ArrowLeft" EXE moveLeft
// UI buttons (text on button)
Button "START" EXE startGame
Button "PAUSE" EXE togglePause
Multiple bindings for the same key/button are allowed — they all fire.
6. Best Practices & Common Pitfalls
- Always balance
=…-blocks - Use parentheses around every expression:
IF (a > b) THN - Prefer named blocks over deep nesting
- Keep functions short (< 30 lines)
- Use
constfor values that never change - Test audio/canvas code with small delays (
WIT 30) - Avoid very long-running loops without
WIT
7. Complete Example Programs
7.1 Simple rhythm game skeleton
EXTRACT math music canvas storage
VAR score 0
const SPEED 180
Button "START" EXE begin
-begin =
music.wave "square"
RRI "Game started!"
- 9999 = // game loop
EXE spawnNote
EXE checkHits
WIT SPEED
-
-
7.2 Bouncing ball animation
EXTRACT canvas math
const W 800 H 500
VAR x 400 y 250
VAR vx 5 vy 3.2
canvas.create "game" W H
const ctx canvas.lastContext
- 9999 =
canvas.clear ctx
canvas.circle ctx x y 18 "#0f8" true
SET x (x + vx)
SET y (y + vy)
IF (x > W-20) OR (x < 20) THN SET vx (vx * -1) END
IF (y > H-20) OR (y < 20) THN SET vy (vy * -1) END
WIT 16
-
8. Quick Syntax Cheatsheet
| What | Syntax |
|---|---|
| Set variable | SET x 10 or x = 10 |
| Expression | (math.sqrt(64) + 5) |
| Block open/close | = … - |
| Named block | -myfunc = … - |
| Call block | EXE myfunc |
| Simple loop n times | - 8 = … - |