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 safe Function sandbox
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

KeywordPurposeArguments / ExampleNotes
VARMutable variableVAR name valueDynamic type
constImmutable variableconst PI 3.14159Local scope only
RRIPrint to outputRRI "Hello" or RRI (score)Appends to #runtime-out
WITDelay (ms)WIT 500await new Promise(r ⇒ setTimeout(r, ms))
EXECall named function/blockEXE updateFrom this.functions
EXTRACTLoad libraryEXTRACT mathMerges into scope
STOStop scriptSTOClears buffers & exits
INPUTUser promptVAR name INPUT "Your name?"Uses window.prompt
SETRe-assign variableSET score (score + 1)More explicit than name = …
ALIASCreate shortcut nameALIAS print RRIUseful 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)

4.5 dom (basic DOM helpers – optional)

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

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

WhatSyntax
Set variableSET x 10 or x = 10
Expression(math.sqrt(64) + 5)
Block open/close=-
Named block-myfunc = … -
Call blockEXE myfunc
Simple loop n times- 8 = … -