BITBOP

BITBOP DOCS

Make, play, and understand.

API Reference

Every learner command, on one page.

Bitbop runs classic ES5 JavaScript inside a preemptable worker. This generated reference is intended for parents, tutors, teachers, and advanced learners who need the exact contract behind each studio command. Use the contents or your browser's Find command to jump directly to a namespace, function, callback, or options type.

Program model

Code runs directly from top to bottom. Use var, function declarations, and function () {} callbacks. Arrow functions, let, const, classes, modules, the DOM, networking, and browser timers are unavailable.

while (true) {
  Turtle.move(5);
  sleep(50);
}

Run creates a fresh realm. Pause freezes continuations and queues input. Step executes one meaningful highlighted source action without waiting for sleeps. Resume continues. Stop discards the realm, callbacks, prompts, sleepers, and sounds.

Status Meaning
Running Statements or an input callback are executing.
Waiting Every runnable continuation is sleeping.
Listening Top-level code finished and callbacks remain available.
Paused Continuations and queued input are suspended.
Done Top-level code finished without callbacks.
Stopped The realm was destroyed.

Coordinates, colors, and notes

Canvas coordinates use a 640×480 learner space with (0, 0) at the top-left. X increases right and Y increases down. Display resizing never changes learner coordinates.

Colors are case-insensitive and accept the complete family of CSS named colors plus #RGB and #RRGGBB. Notes accept names such as C4, F#3, and Db5, or MIDI numbers from 0 through 127.

Input lifecycle

A later registration replaces the earlier callback of the same kind. Input callbacks keep completed code in Listening. Paused input queues in order and can be executed with Step while preserving source highlighting and local-scope Console inspection. Stop, an error, or a fresh Run clears callbacks.

Console and errors

The lower Console runs snippets in the current realm. After Step or a debugger; statement, it uses the highlighted line's local scope. You can inspect or assign variables before Resume. Autocomplete reflects the interpreter's supported Bitbop and JavaScript globals, nested members, parameters, local variables, and runtime-known object members. Functions offer classic-JavaScript call snippets and concise help. Variable values stay inside the worker. Resume and Stop return the Console to Global. A later pause sets a new local scope. Runtime and syntax errors keep their short original message. Bitbop adds a plain-language suggestion and highlights the source line without moving the workspace.

Use JavaScript's debugger; statement to pause at a chosen point. Bitbop highlights that line and keeps its scope for the Console. Put the statement in an if block to pause only when a condition is true:

if (mark === 17) {
  debugger;
}

debugger; belongs in the Code editor, not in a Console snippet. Step runs the next meaningful statement. Resume continues normal execution.

Limits

The worker yields after at most 1,600 interpreter steps or roughly 6 milliseconds. Two million continuous steps without a wait trigger a friendly watchdog error. Console output, rendering queues, Paint strokes, audio voices, prompts, projects, and share URLs are bounded. The learner realm cannot access the browser DOM, host globals, network, or storage.

Globals

#sleep(milliseconds) → undefined

Suspend only the current continuation. Other input callbacks can still run. Step advances through a sleep without waiting.

NameTypeMeaning
millisecondsnumber

A duration from 0 through 60000, or Infinity to sleep forever.

Returns undefined
while (true) {
  Turtle.move(4);
  sleep(50);
}

#prompt([message=''], [defaultValue='']) → string | null

Ask the learner for text in Bitbop's accessible modal dialog. The entire realm pauses while the question is open.

NameTypeMeaning
[message='']string

Question text, truncated to 240 characters.

[defaultValue='']string

Initial answer, truncated to 500 characters.

Returns string | null

The submitted string, including an empty string, or null after Cancel or Escape.

Board

Fixed, project-persistent hardware controls. Callback registration is replaced on the next registration and cleared by Stop or a fresh Run.

Canvas

Pointer input for games and direct-manipulation projects. Registering any callback claims pointer input until Stop, an error, or a fresh Run.

#Canvas.width: number

Learner width in pixels.

#Canvas.height: number

Learner height in pixels.

#Canvas.onClick(callback) → undefined

Register a primary-pointer click callback. Moving eight learner pixels suppresses Click.

NameType
callbackCanvasPointerCallback
Returns undefined

#Canvas.onPress(callback) → undefined

Register a callback for the start of a primary mouse, finger, or pen gesture.

NameType
callbackCanvasPointerCallback
Returns undefined

#Canvas.onDrag(callback) → undefined

Register a drag callback. Movement begins at eight learner pixels and is coalesced to once per display frame.

NameType
callbackCanvasPointerCallback
Returns undefined

#Canvas.onRelease(callback) → undefined

Register a release or cancellation callback. A pending final Drag is delivered first.

NameType
callbackCanvasPointerCallback
Returns undefined

Turtle

A pen-carrying cursor on the transparent layer above Paint. It begins at (320, 240), facing up, with its pen down.

#Turtle.reset() → undefined

Clear Turtle art and restore its starting state without changing Paint.

Returns undefined

#Turtle.home() → undefined

Move to the center facing up without drawing or clearing.

Returns undefined

#Turtle.penDown() → undefined

Draw during future movement.

Returns undefined

#Turtle.penUp() → undefined

Move without drawing.

Returns undefined

#Turtle.color(color) → undefined

Set a case-insensitive CSS color name, #RGB, or #RRGGBB.

NameType
colorstring
Returns undefined

#Turtle.width(pixels) → undefined

Set line width, clamped from 1 through 50. Non-finite values leave it unchanged.

NameType
pixelsnumber
Returns undefined

#Turtle.turn(degrees) → undefined

Turn clockwise for positive values.

NameTypeMeaning
degreesnumber

A finite number.

Returns undefined

#Turtle.move(distance) → undefined

Move in the current heading and draw when the pen is down.

NameTypeMeaning
distancenumber

A finite number.

Returns undefined

Paint

Persistent bitmap drawing beneath Turtle.

#Paint.clear() → undefined

Clear only the Paint bitmap.

Returns undefined

#Paint.stroke(points, [options]) → undefined

Draw a connected stroke of at most 5000 points.

NameType
pointsArray.<Point>
[options]StrokeOptions
Returns undefined

#Paint.fill(x, y, color) → undefined

Flood-fill a bounded region without blocking the controls.

NameTypeMeaning
xnumber
ynumber
colorstring

CSS name, #RGB, or #RRGGBB.

Returns undefined

Music

Sixteen-voice WebAudio synthesizer. Browser audio is unlocked by the intentional Run, Step, Resume, or piano gesture.

#Music.play(note, [seconds=0], [options]) → number

Start a voice. Durations at or below zero sustain until stopped.

NameType
noteNote
[seconds=0]number
[options]MusicOptions
Returns number

Numeric voice handle.

#Music.stop(handleOrNote) → undefined

Release one handle or every voice matching a note.

NameType
handleOrNotenumber | Note
Returns undefined

#Music.stopAll() → undefined

Release every voice.

Returns undefined

#Music.setInstrument(type) → undefined

Set the default waveform.

NameType
type'sine' | 'square' | 'sawtooth' | 'triangle'
Returns undefined

#Music.setVolume(value) → undefined

Set default volume, clamped from 0 through 1.

NameType
valuenumber
Returns undefined

#Music.setEnvelope(options) → undefined

Set default attack and release times.

NameType
optionsEnvelopeOptions
Returns undefined

Keyboard

Events from the visible virtual piano.

#Keyboard.onPress(callback) → undefined

Replace the callback run when a piano note starts.

NameType
callbackNoteCallback
Returns undefined

#Keyboard.onRelease(callback) → undefined

Replace the callback run when a piano note ends.

NameType
callbackNoteCallback
Returns undefined

UI

Programmatic control of the five content panels. State is shared with the Panels menu and saved in the project.

#UI.show(name) → boolean

Show a panel.

NameType
namePanelName
Returns boolean

Always true.

#UI.hide(name) → boolean

Hide a panel.

NameType
namePanelName
Returns boolean

Always false.

#UI.isVisible(name) → boolean

Read current panel visibility.

NameType
namePanelName
Returns boolean

Console

Bounded output displayed by Bitbop's Console panel.

#console.log(...values) → undefined

NameTypeMeaning
...values*

Values to display.

Returns undefined

#console.warn(...values) → undefined

NameTypeMeaning
...values*

Warning values to display.

Returns undefined

#console.error(...values) → undefined

NameTypeMeaning
...values*

Error values to display.

Returns undefined

Types

#Note: string | number

A note name such as C4, F#3, or Db5, or a MIDI number from 0 through 127.

#PanelName: 'code' | 'controls' | 'canvas' | 'piano' | 'console'

A visible workspace panel.

#Point: Object

A canvas coordinate.

NameTypeMeaning
xnumber

Horizontal coordinate from the left.

ynumber

Vertical coordinate from the top.

#StrokeOptions: Object

Options for Paint.stroke.

NameTypeMeaning
[color='#000000']string

A CSS color name, #RGB, or #RRGGBB.

[width=1]number

Stroke width in learner pixels.

[alpha=1]number

Opacity from 0 through 1.

#MusicOptions: Object

Options for Music.play.

NameTypeMeaning
[type]'sine' | 'square' | 'sawtooth' | 'triangle'

Waveform for this voice.

[volume]number

Voice volume from 0 through 1.

[attack]number

Attack time in seconds.

[release]number

Release time in seconds.

#EnvelopeOptions: Object

Default synthesizer envelope values.

NameTypeMeaning
[attack]number

Attack time in seconds.

[release]number

Release time in seconds.

#CanvasPointerEvent: Object

Details supplied to a Canvas pointer callback. All coordinates are rounded and clamped to the 640×480 learner canvas.

NameTypeMeaning
type'click' | 'press' | 'drag' | 'release'

Event kind.

xnumber

Current horizontal coordinate from 0 through 639.

ynumber

Current vertical coordinate from 0 through 479.

startXnumber

Horizontal coordinate where the gesture began.

startYnumber

Vertical coordinate where the gesture began.

dxnumber

Horizontal movement since the gesture began.

dynumber

Vertical movement since the gesture began.

#EmptyCallback() → undefined

Returns undefined

#ValueCallback(value) → undefined

NameTypeMeaning
valueboolean | number

The control's new value.

Returns undefined

#NoteCallback(note) → undefined

NameTypeMeaning
notestring

Note name such as C4.

Returns undefined

#CanvasPointerCallback(event) → undefined

NameTypeMeaning
eventCanvasPointerEvent

Pointer details.

Returns undefined

#ButtonControl: Object

A momentary Control Board button.

NameTypeMeaning
valueboolean

true while held; otherwise false.

onPressfunction

Replaces the callback run when the button is pressed.

onReleasefunction

Replaces the callback run when the button is released.

#ToggleControl: Object

A latched Control Board switch.

NameTypeMeaning
valueboolean

Current switch state.

onChangefunction

Replaces the callback receiving the new Boolean state.

#SliderControl: Object

A Control Board slider.

NameTypeMeaning
valuenumber

Current integer from 0 through 100.

onChangefunction

Replaces the callback receiving new values while the slider moves.