Skip to content

Script globals

Updated

The names a Behavior script sees, read from the runtime’s BehaviorGlobals type. The Globals guide groups them by purpose and links each to its page.

Name Description
ASSERT Throw Assertion failed when the condition is false.
audioListener Shared listener attached to the active camera; live, undefined until rendering starts.
AvatarAppearance
Avatars Account avatar operations supplied by the host.
camera The camera the player sees through
CameraDirector Cut between cameras by name or id: switchTo(name), switchToMain(); current and main are the camera entities.
Canvas Canvases for scripts that draw their own images: labels, minimaps, dynamic textures.
Chat Optional host chat service; explicit connect respects the Play/drawn-scene gate.
console The app logger, with the usual console methods.
CoordinateSpace Conversions between the screen, the world, and an object’s own space.
debounce
DEG_TO_RAD Convert degrees to radians.
delay
destroy Same as scene.destroy: remove an entity (or id) and its subtree, disposing them and stopping their scripts.
Device Platform facts for scripts that adapt to the device they run on.
Ease The easings, for { ease: Ease.OutCubic }: Linear, and In, Out and InOut of each curve (Quad, Cubic, Quart, Sine, Expo, Back, Elastic, Bounce). In starts slow, Out ends slow, InOut does both; Back overshoots a little, Elastic springs, Bounce bounces. Any function of progress 0..1 works as well.
Editor Editor tools only (#editor_only, #editor_begin): selection(), select(entities), camera. Throws in play.
emit Raise a signal, with optional data, for every script and the app.
Environment Project variables, read only: Environment.get(name, fallback) returns the loaded value or fallback when absent or still an unresolved reference.
EPSILON Float tolerance for positions and angles (1e-6).
EventType Every event type a script can hear, by who sends it: compare them rather than typing the strings.
findObject Find any object in the current scene by name, a bone or a mesh inside a model too. Walks the scene: look up once and keep it.
Fonts The app’s font families: await Fonts.register(family, url, { weight, label }) for this session, unregister, has(family), families.
GraphicsRaycaster A ray against what is drawn: meshes, lines, points and sprites, down to the triangle. A native THREE.Raycaster; see Raycaster for how to use it. Hidden objects and objects excluded by the current local view are never hit.
Haptics Vibration on whatever the player has: XR controllers in an XR session, a gamepad’s rumble when one is connected, the phone otherwise.
HttpRequest HTTP requests, cancelled when the script is released: get, post, …, request, and extend for a client with its own defaults.
Input Every input device: keyboard, mouse, touch, XR, accelerometer, gyroscope, microphone, device camera, location.
Key Defines the values for standard keys
log Write values to the script log.
Logger The app logger: log, info, warn, error. Also reachable as console.
M_HALF_PI π/2, a quarter turn in radians.
M_PI π, half a turn in radians.
M_TAU 2π, a full turn in radians.
MAX_INT Largest safe integer (Number.MAX_SAFE_INTEGER).
MIN_INT Smallest safe integer (Number.MIN_SAFE_INTEGER).
MouseButton The MouseButton enum provides constants representing the different mouse buttons.
Network Replicate objects and traits: replicate(object, options), unreplicate, of, define(kind, build, setup), spawn(kind, data, options), subscribe(partition), unsubscribe(partition); connected, peerId, peers, peerCount, interestCenter.
NetworkCommand Every command the room server defines: Network.command(NetworkCommand.ReactionSend, { reaction: '👍' }).
NetworkTraitType Every trait a Networkable can replicate: traits: [NetworkTraitType.Transform, NetworkTraitType.PointLight].
NotificationService Notifications, passive or asking: show(type, data, { anchor | position, duration, signal }), the answer on signal; update(id, data, options), define(key, build), dismiss(type), has, isOpen.
NotificationType The built-in notifications: Info, Success, Warning, Error, Compact.
ObjectPool Reuses objects instead of creating and discarding them, for things that come and go often: bullets, particles, floating damage numbers.
off Stop every listener this script added with on or once for signal; other scripts keep theirs.
on Call callback(data) right away each time signal is emitted; returns a function that stops it. Released with the script.
once Call callback(data) the next time signal is emitted, then stop; returns a function that stops it sooner. Released with the script.
Participants
PhysicsRaycaster A ray against colliders, in the physics world: one query over a few simple shapes instead of every triangle, and exactly what the physics blocks. A native THREE.Raycaster too; see Raycaster for how to use it.
RAD_TO_DEG Convert radians to degrees.
Random The shared generator scripts use as Random: every method, with examples, is on RandomGenerator. Frozen, so no script can change it for the others.
scene The current scene fragment; live, so it always reflects the loaded scene. To delete an entity use scene.destroy(entity): it stops its scripts and frees its memory. scene.remove(entity) (and scene.clear()) stop the scripts but keep the memory, for an entity you will add back later.
Scenes Switch scenes: await Scenes.load(id), load(id, { additive: true }), unload(id), list(), active().
SCRIPTING_RUNTIME_VERSION Version number of the scripting runtime.
self The entity the Behavior is on: self.position, self.getComponent(...). Its own Behavior is self.getComponent(BehaviorComponent).
ShaderPreset The app’s shader presets, by name: ShaderPreset.list(), get(name), register(source); a Shader Material draws one with setProps({ preset: name }).
Singleton Named shared instances for this app: Singleton.get(key, factory), then Singleton.key.
spawn Copy an entity already in the scene (by name, or the entity itself) and add the copy with options.
Streams Live streams by name, for Media Stream components: create(id, { video, audio }) then writeVideoFrame / writeAudioFrame, publish(id, Input.camera.stream()), ids(), has(id), on(id, live => …). Optional RTC: room.state, room.subscribe, room.connect/disconnect, and explicit await room.publish(source) / await room.unpublish(source) for mic, camera and screen.
SURL Route a URL through the configured CORS proxy. Exposed to scripts as SURL.
THREE Raw three.js in a Behavior: meshes, materials, vectors, colours and math.
throttle
Time Measure with Time.now(), Time.since(start); game time: Time.scale, pause(), resume(), isPaused().
Torch The phone’s torch, by its back camera: await Torch.on(), off(), toggle(), isOn().
Tween Animate any object’s numbers: Tween.to(mesh.position, { x: 5 }, { duration: 1 }), from, value, stop; awaitable.
WebBrowser Read the browser location and open new tabs.
XRButton
XRRaycaster A ray against the real world, asked of the device (a WebXR hit test): the floor, walls, tables and anything else it understands, in an immersive session. The device only casts from what it tracks, so the rays start there:

Every component and entity class is a global too (315 names), for getComponent, addComponent and instanceof. See the component reference and the entity reference.