Globals and Constants
SCRIPTING_RUNTIME_REV
Represents the current scripting runtime revision number.
This constant can be used to:
- Check compatibility with specific runtime features.
- Apply conditional logic for backward/forward compatibility.
- Provide fallbacks for older runtime environments.
Example:
if (SCRIPTING_RUNTIME_REV < 5) {
console.warn("This feature requires runtime revision 5 or later.");
} else {
enableAdvancedFeature();
}
M_PI
A constant representing the mathematical value of π (3.14159...
).
Example:
const circumference = 2 * M_PI * radius;
MAX_INT
A constant representing the maximum value that a signed 32-bit integer can hold (2,147,483,647
).
Example:
if (value > MAX_INT) {
throw new Error("Value exceeds 32-bit integer range.");
}
MIN_INT
A constant representing the minimum value that a signed 32-bit integer can hold (-2,147,483,648
).
Example:
if (value < MIN_INT) {
throw new Error("Value is below 32-bit integer range.");
}
DEBUG
Indicates whether the application is running in debug mode.
This is useful for enabling additional logging, profiling, or diagnostics.
Example:
if (DEBUG) {
console.log("Debugging enabled – verbose logs will be shown.");
}
EDITOR
Indicates whether the application is running inside an editor environment (as opposed to runtime).
Use Case:
Enable editor-only tools, UI panels, or debugging overlays.
Example:
if (EDITOR) {
showEditorToolbar();
}
IS_MOBILE
Indicates whether the current device is a mobile platform.
Example:
if (IS_MOBILE) {
enableTouchControls();
} else {
enableKeyboardControls();
}
PLATFORM_WINDOWS
Indicates whether the current operating system is Windows.
Example:
if (PLATFORM_WINDOWS) {
console.log("Running on Windows");
}
PLATFORM_MACOS
Indicates whether the current operating system is macOS.
Example:
if (PLATFORM_MACOS) {
console.log("Running on macOS");
}
PLATFORM_LINUX
Indicates whether the current operating system is Linux.
Example:
if (PLATFORM_LINUX) {
console.log("Running on Linux");
}
PLATFORM_ANDROID
Indicates whether the current operating system is Android.
Example:
if (PLATFORM_ANDROID) {
console.log("Running on Android");
}
PLATFORM_IOS
Indicates whether the current operating system is iOS.
Example:
if (PLATFORM_IOS) {
console.log("Running on iOS");
}
DEG_TO_RAD(x: number): number
Converts an angle from degrees to radians.
Example:
const radians = DEG_TO_RAD(90); // 1.5708 (π/2)
RAD_TO_DEG(x: number): number
Converts an angle from radians to degrees.
Example:
const degrees = RAD_TO_DEG(M_PI); // 180
ASSERT(x: any): void
Checks if a condition is truthy and throws an error if not.
Example:
ASSERT(player != null); // Throws error if player is null
SURL(url: string): string
Converts a URL to a sandboxed safe URL, ensuring it is properly encoded. This function is useful for normalizing URLs before making requests.
Example:
const safeUrl = SURL("https://example.com/unsafe?param=hello world");
fetch(safeUrl);
self
This is a self reference to the Behaviour element in the current context.
It's used to access and manipulate properties or methods related to the Behaviour.
Example:
self.position.set(0, 1, 0);
self.rotateY(Math.PI / 2);
scene
A reference to the global THREE.Scene object. This is the central container for all 3D elements in your application, allowing you to dynamically add, remove, and modify objects within the scene.
Example:
scene.add(new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshBasicMaterial()));
scene.remove(oldObject);
camera
Provides global access to the scene's THREE.Camera. It's used to configure and manipulate the camera's properties.
Example:
camera.position.set(0, 5, 10);
camera.lookAt(0, 0, 0);
audioListener
Provides global access to the THREE.AudioListener instance attached to the camera. It's essential for managing and creating dynamic audio sources within the 3D scene.
Example:
const sound = new THREE.Audio(audioListener);
sound.setBuffer(audioBuffer);
sound.play();