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.
Runtime APIs and constants
Section titled “Runtime APIs and constants”| Name | Description |
|---|---|
ASSERT |
Throw Assertion failed when the condition is false. |
audioListener |
Shared listener attached to the active camera; live, undefined until rendering starts. |
Avatar |
|
Avatars |
Account avatar operations supplied by the host. |
camera |
The camera the player sees through |
Camera |
Cut between cameras by name or id: switch, switch; 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. |
Coordinate |
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.: 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. 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. for this session, unregister, has(family), families. |
Graphics |
A ray against what is drawn: meshes, lines, points and sprites, down to the triangle. A native THREE.; 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, interest. |
Network |
Every command the room server defines: Network.. |
Network |
Every trait a Networkable can replicate: traits: [Network. |
Notification |
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. |
Notification |
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 |
|
Physics |
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. 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 Random. 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.: it stops its scripts and frees its memory. scene. (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, { additive: true }), unload(id), list(), active(). |
SCRIPTING_ |
Version number of the scripting runtime. |
self |
The entity the Behavior is on: self.position, self.. Its own Behavior is self.. |
ShaderPreset |
The app’s shader presets, by name: Shader, get(name), register(source); a Shader Material draws one with set. |
Singleton |
Named shared instances for this app: Singleton., 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 write / write, publish(id, Input., ids(), has(id), on(id, live => …). Optional RTC: room.state, room., room., and explicit await room. / await room. 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.; game time: Time.scale, pause(), resume(), isPaused(). |
Torch |
The phone’s torch, by its back camera: await Torch., off(), toggle(), isOn(). |
Tween |
Animate any object’s numbers: Tween., 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: |
Component and entity classes
Section titled “Component and entity classes”Every component and entity class is a global too (315 names), for getComponent, addComponent and instanceof. See the component reference and the entity reference.