The global namespace in a Lens provides utilities and information about the current state of the Lens.
| API | Description |
|---|---|
| failAsync | Unhandled Promise rejections are silently ignored by default.failAsync rethrows the error, ensuring it results in an unhandled exception. Note: error is not rethrown immediately, some pending JS code might still be executed.Use it as a default .catch() handler when no other error handling is provided.Example: js<br>someAsyncFunction().catch(failAsync);<br> |
| getAbsoluteStartTime | The start time of the Lens since UNIX Epoch. |
| getDeltaTime | Returns the time difference in seconds between the current frame and previous frame. |
| getRealTimeNanos | Get current time in Nanoseconds. Useful when optimizing a Lens to understand its performance. |
| getTime | Returns the time in seconds since the lens was started. |
| isNull | Returns true if the passed in object is null or destroyed. Useful as a safe way to check if a SceneObject or Component has been destroyed. |
| Prints out a message to the Logger window. | |
| require | Load a JavaScript module. Used for importing another JavaScript file found in the Resources panel to be used in the current script. Similar to require found in CommonJS specification. You can access Lens Studio specific modules (like RemoteServiceModule) using the LensStudio prefix, such as: require("LensStudio:RemoteServiceModule).You can use the modules name or path, meaning you can have two version of the same module in your project if needed. Both by name or by path will be relative to the script which is calling require, but by name will check the same folder as the script, then the parent folder, and so on. In addition, any require can be relative to your library folder. Take a look at the Scripting guide to learn more. |
| requireAsset | Load an asset like a Texture, Material, or MLAsset directly from script.You can use the modules name or path. Both by name or by path will be relative to the script which is calling require, but by name will check the same folder as the script, then the parent folder, and so on. In addition, any require can be relative to your library folder. Take a look at the Scripting guide to learn more. |
| requireType | Load a script by name or path in order to use that type to create or get a component at runtime. You can use the modules name or path. Both by name or by path will be relative to the script which is calling require, but by name will check the same folder as the script, then the parent folder, and so on. In addition, any require can be relative to your library folder. Take a look at the Scripting guide to learn more. |
| global.debugRenderSystem | Returns the DebugRender, which provides methods to draw primitive visuals for debugging. |
| global.deviceInfoSystem | Returns the global DeviceInfoSystem, which provides information about the device running the Lens. |
| global.hapticFeedbackSystem | No Comments |
| global.launchParams | Returns the global GeneralDataStore for Launch Params, which provides any special data passed in when the Lens is launched. |
| global.localizationSystem | Returns the global LocalizationSystem, which helps convert times, dates, and other units to user friendly strings. |
| global.persistentStorageSystem | Returns the global PersistentStorageSystem, which allows data to persist between Lens sessions. |
| global.scene | Returns the global ScriptScene object, which offers information and controls for the current scene. |
| global.textInputSystem | No Comments |
| global.touchSystem | Returns the global TouchDataProvider, which controls how the Lens handles touch events. |
| global.userContextSystem | Returns the global UserContextSystem, which provides information about the user such as display name, birthday, and even current weather. |