Script

Description

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts

The Script API provides facilities for working with scripts.

Properties

Name Type Summary
context string

The context that the script is running in:

  • "client": An Interface or avatar script.
  • "entity_client": A client entity script.
  • "entity_server": A server entity script.
  • "agent": An assignment client script.
Read-only.
type string

The type of script that is running:

  • "client": An Interface script.
  • "entity_client": A client entity script.
  • "avatar": An avatar script.
  • "entity_server": A server entity script.
  • "agent": An assignment client script.
Read-only.
filename string

The filename of the script file. Read-only.

ExternalPaths Script.ResourceBuckets

External resource buckets.

Methods

Name Return Value Summary
_requireResolve string

Deprecated: This function is deprecated and will be removed.

addEventHandler None

Adds a function to the list of functions called when a particular event occurs on a particular entity.

See also, the Entities API.

atob ArrayBuffer

This decodes Base64 string and returns contents as ArrayBuffer.

beginProfileRange None

Starts timing a section of code in order to send usage data about it to Overte. Shouldn't be used outside of the standard scripts.

btoa String

This encodes ArrayBuffer and returns Base64-encoded string.

callEntityScriptMethod None

Calls a method in an entity script.

callEntityScriptMethod None

Calls a method in an entity script.

Deprecated: This function is deprecated and will be removed.

callEntityScriptMethod None

Calls a method in an entity script.

Deprecated: This function is deprecated and will be removed.

clearInterval None

Stops an interval timer set by setInterval.

clearTimeout None

Stops a timeout timer set by setTimeout.

createGarbageCollectorDebuggingObject()

Create test object for garbage collector debugging.

dumpHeapObjectStatistics None

Prints heap statistics to a file. Collecting needs to first be started with Script.dumpHeapObjectStatistics().

endProfileRange None

Finishes timing a section of code in order to send usage data about it to Overte. Shouldn't be used outside of the standard scripts.

entityScriptContentAvailable None

Deprecated: This function is deprecated and will be removed.

executeOnScriptThread None

Deprecated: This function is deprecated and will be removed.

formatExecption string

Deprecated: This function is deprecated and will be removed.

generateUUID Uuid

Deprecated: This function is deprecated and will be removed. Use Uuid.generate instead.

getContext string

Gets the context that the script is running in: Interface/avatar, client entity, server entity, or assignment client.

getExternalPath string

Gets the URL for an asset in an external resource bucket. (The location where the bucket is hosted may change over time but this method will return the asset's current URL.)

getMemoryUsageStatistics Script.MemoryUsageData

Returns memory usage statistics data.

include None

Includes JavaScript from another file in the current script. If a callback is specified, the file is loaded and included asynchronously, otherwise it is included synchronously (i.e., script execution blocks while the file is included).

include None

Includes JavaScript from other files in the current script. If a callback is specified, the files are loaded and included asynchronously, otherwise they are included synchronously (i.e., script execution blocks while the files are included).

isAgentScript boolean

Checks whether the script is running as an assignment client script.

isClientScript boolean

Checks whether the script is running as an Interface or avatar script.

isDebugMode boolean

Checks whether the application was compiled as a debug build.

isEntityClientScript boolean

Checks whether the script is running as a client entity script.

isEntityScriptRunning boolean

Checks whether an entity has an entity script running.

isEntityServerScript boolean

Checks whether the script is running as a server entity script.

load None

Starts running another script in Interface, if it isn't already running. The script is not automatically loaded next time Interface starts.

Supported Script Types: Interface Scripts • Avatar Scripts

See also, ScriptDiscoveryService.loadScript.

loadEntityScript None

Deprecated: This function is deprecated and will be removed.

logBacktrace None

Prints out current backtrace to the log.

print None

Prints a message to the program log and emits Script.printedMessage.

Alternatively, you can use print or one of the console API methods.

registerValue None

registers a global object by name.

removeEventHandler None

Removes a function from the list of functions called when an entity event occurs on a particular entity.

See also, the Entities API.

requestGarbageCollection None

Manually runs the JavaScript garbage collector which reclaims memory by disposing of objects that are no longer reachable.

require object | array

Provides access to methods or objects provided in an external JavaScript or JSON file. See https://docs.overte.org/script/js-tips.html for further details.

resetModuleCache None

Deprecated: This function is deprecated and will be removed.

resolvePath string

Resolves a relative path to an absolute path. The relative path is relative to the script's location.

resourcesPath string

Gets the path to the resources directory for QML files.

setInterval object

Calls a function repeatedly, at a set interval.

setTimeout object

Calls a function once, after a delay.

startCollectingObjectStatistics None

Start collecting object statistics that can later be reported with Script.dumpHeapObjectStatistics().

startProfiling None

Starts collecting profiling data

stop None

Stops and unloads the current script.

Warning: If an assignment client script, the script gets restarted after stopping.

stopProfilingAndSave None

Stops collecting profiling data and writes them to a timestamped CSV file in Logs directory.

subscribeToServerEntityScriptMessages None

After calling this function current script engine will start receiving server-side entity script messages through signals such as errorEntityMessage. This function can be invoked both from client-side entity scripts and from interface scripts.

unloadAllEntityScripts None

Deprecated: This function is deprecated and will be removed.

unloadEntityScript None

Deprecated: This function is deprecated and will be removed.

unsubscribeFromServerEntityScriptMessages None

Calling this function signalizes that current script doesn't require stop receiving server-side entity script messages through signals such as errorEntityMessage. This function can be invoked both from client-side entity scripts and from interface scripts.

Signals

Name Summary
clearDebugWindow

Deprecated: This signal is deprecated and will be removed.

doneRunning

Triggered when the script has stopped.

entityScriptDetailsUpdated

Deprecated: This signal is deprecated and will be removed.

entityScriptPreloadFinished

Triggered when the script starts for the user. See also, Entities.preload.

Supported Script Types: Client Entity Scripts • Server Entity Scripts

errorLoadingScript

Deprecated: This signal is deprecated and will be removed.

errorMessage

Triggered when a client side entity script generates an error, console.error or console.exception is called, or console.assert is called and fails.

errorMessage

Triggered when the script generates an error, console.error or console.exception is called, or console.assert is called and fails.

infoMessage

Triggered when a client side entity script generates an information message or console.info is called.

infoMessage

Triggered when the script generates an information message or console.info is called.

loadScript

Deprecated: This signal is deprecated and will be removed.

printedMessage

Triggered when a client side entity script prints a message to the program log via print, Script.print, console.log, console.debug, console.group, console.groupEnd, console.time, or console.timeEnd.

printedMessage

Triggered when the script prints a message to the program log via print, Script.print, console.log, console.debug, console.group, console.groupEnd, console.time, or console.timeEnd.

reloadScript

Deprecated: This signal is deprecated and will be removed.

runningStateChanged

Triggered when the running state of the script changes, e.g., from running to stopping.

scriptEnding

Triggered when the script is stopping.

scriptLoaded

Deprecated: This signal is deprecated and will be removed.

unhandledException

Triggered when a script generates an unhandled exception.

update

Triggered frequently at a system-determined interval.

warningMessage

Triggered when a client side entity script generates a warning or console.warn is called.

warningMessage

Triggered when the script generates a warning or console.warn is called.

Type Definitions

EntityEvent
Type: string

The name of an entity event. When the entity event occurs, any function that has been registered for that event via Script.addEventHandler is called with parameters per the entity event.

Event NameCallback TypeEntity Event
"enterEntity"entityEventCallback Entities.enterEntity
"leaveEntity"entityEventCallback Entities.leaveEntity
"mousePressOnEntity"pointerEventCallback Entities.mousePressOnEntity
"mouseMoveOnEntity"pointerEventCallback Entities.mouseMoveOnEntity
"mouseReleaseOnEntity"pointerEventCallback Entities.mouseReleaseOnEntity
"clickDownOnEntity"pointerEventCallback Entities.clickDownOnEntity
"holdingClickOnEntity"pointerEventCallback Entities.holdingClickOnEntity
"clickReleaseOnEntity"pointerEventCallback Entities.clickReleaseOnEntity
"hoverEnterEntity"pointerEventCallback Entities.hoverEnterEntity
"hoverOverEntity"pointerEventCallback Entities.hoverOverEntity
"hoverLeaveEntity"pointerEventCallback Entities.hoverLeaveEntity
"collisionWithEntity"collisionEventCallback Entities.collisionWithEntity
MemoryUsageData
Type: object

Object containing memory usage statistics data.

Amount of heap memory that is currently in use.
NameTypeDescription
totalHeapSize{number}Total heap size allocated by scripting engine.
usedHeapSize{number}
totalAvailableSize{number}Amount of remaining available heap memory
totalGlobalHandlesSize{number}V8-specific property
usedGlobalHandlesSize{number}V8-specific property
ResourceBucket
Type: number

An external resource bucket.

ValueNameDescription
0HF_PublicAssets that used to be in High Fidelity's hifi-public Amazon S3 bucket.
1HF_ContentAssets that used to be in High Fidelity's hifi-content Amazon S3 bucket.
2HF_MarketplaceAssets that used to be in the High Fidelity's mpassets Amazon S3 bucket. (High Fidelity marketplace.)
3AssetsOverte assets.
ResourceBuckets
Type: object

An external resource bucket.

The original High Fidelity used "Public", "Content", and "MPAssets" Amazon S3 buckets. The intention is that the community-run versions of these will keep the original data and structure, and any new additions will be made to Overte's "Assets" bucket. This should ease the transition from High Fidelity and ensure a clean separation.

Properties

Name Type Summary
Assets Script.ResourceBucket

Overte assets.

HF_Public Script.ResourceBucket

Assets that used to be in High Fidelity's hifi-public Amazon S3 bucket.

HF_Content Script.ResourceBucket

Assets that used to be in High Fidelity's hifi-content Amazon S3 bucket.

HF_Marketplace Script.ResourceBucket

Assets that used to be in the High Fidelity's mpassets Amazon S3 bucket. (High Fidelity marketplace.)

collisionEventCallback( entityA, entityB, collisionEvent )
Type: function

Called when a collision event occurs on an entity as registered with Script.addEventHandler.

Parameters

Name Type Description
entityA Uuid

The ID of one entity in the collision.

entityB Uuid

The ID of the other entity in the collision.

collisionEvent Collision

Details of the collision.

entityEventCallback( entityID )
Type: function

Called when an entity event occurs on an entity as registered with Script.addEventHandler.

Parameters

Name Type Description
entityID Uuid

The ID of the entity the event has occured on.

pointerEventCallback( entityID, pointerEvent )
Type: function

Called when a pointer event occurs on an entity as registered with Script.addEventHandler.

Parameters

Name Type Description
entityID Uuid

The ID of the entity the event has occurred on.

pointerEvent PointerEvent

Details of the event.

Method Details

(static) _requireResolve( module, relativeToopt ) → {string}
Returns: Result.

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Attributes Default Value Description
module string

Module.

relativeTo string <optional>
""

Relative to.

(static) addEventHandler( entityID, eventName, handler )

Adds a function to the list of functions called when a particular event occurs on a particular entity.

See also, the Entities API.

Parameters

Name Type Description
entityID Uuid

The ID of the entity.

eventName Script.EntityEvent

The name of the event.

handler Script~entityEventCallback | Script~pointerEventCallback | Script~collisionEventCallback

The function to call when the event occurs on the entity. It can be either the name of a function or an in-line definition.

Example

Report when a mouse press occurs on a particular entity.

var entityID = Entities.addEntity({
    type: "Box",
    position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5 })),
    dimensions: { x: 0.5, y: 0.5, z: 0.5 },
    lifetime: 300  // Delete after 5 minutes.
});

function reportMousePress(entityID, event) {
    print("Mouse pressed on entity: " + JSON.stringify(event));
}

Script.addEventHandler(entityID, "mousePressOnEntity", reportMousePress);
(static) atob( base64 ) → {ArrayBuffer}
Returns: Decoded binary data.

This decodes Base64 string and returns contents as ArrayBuffer.

Parameters

Name Type Description
base64 String

String with Base64-encoded binary data.

(static) beginProfileRange( label )

Starts timing a section of code in order to send usage data about it to Overte. Shouldn't be used outside of the standard scripts.

Parameters

Name Type Description
label string

A name that identifies the section of code.

(static) btoa( binary ) → {String}
Returns: String with Base64-encoded binary data.

This encodes ArrayBuffer and returns Base64-encoded string.

Parameters

Name Type Description
binary ArrayBuffer

Data to be encoded.

(static) callEntityScriptMethod( entityID, methodName, parametersopt, remoteCallerIDopt )

Calls a method in an entity script.

Parameters

Name Type Attributes Default Value Description
entityID Uuid

The ID of the entity running the entity script.

methodName string

The name of the method to call.

parameters Array.<string> <optional>
[]

The parameters to call the specified method with.

remoteCallerID Uuid <optional>
Uuid.NULL

An ID that identifies the caller.

(static) callEntityScriptMethod( entityID, methodName, event )

Calls a method in an entity script.

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
entityID Uuid

Entity ID.

methodName string

Method name.

event PointerEvent

Pointer event.

(static) callEntityScriptMethod( entityID, methodName, otherID, collision )

Calls a method in an entity script.

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
entityID Uuid

Entity ID.

methodName string

Method name.

otherID Uuid

Other entity ID.

collision Collision

Collision.

(static) clearInterval( timer )

Stops an interval timer set by setInterval.

Parameters

Name Type Description
timer object

The interval timer to stop.

Example

Stop an interval timer.

// Print a message every second.
var timer = Script.setInterval(function () {
    print("Interval timer fired");
}, 1000);

// Stop the timer after 10 seconds.
Script.setTimeout(function () {
    print("Stop interval timer");
    Script.clearInterval(timer);
}, 10000);
(static) clearTimeout( timer )

Stops a timeout timer set by setTimeout.

Parameters

Name Type Description
timer object

The timeout timer to stop.

Example

Stop a timeout timer.

// Print a message after two seconds.
var timer = Script.setTimeout(function () {
    print("Timer fired");
}, 2000);

// Uncomment the following line to stop the timer from firing.
//Script.clearTimeout(timer);
(static) createGarbageCollectorDebuggingObject()( )
Returns: Test object.

Create test object for garbage collector debugging.

(static) dumpHeapObjectStatistics( )

Prints heap statistics to a file. Collecting needs to first be started with Script.dumpHeapObjectStatistics().

(static) endProfileRange( label )

Finishes timing a section of code in order to send usage data about it to Overte. Shouldn't be used outside of the standard scripts.

Parameters

Name Type Description
label string

A name that identifies the section of code.

(static) entityScriptContentAvailable( entityID, scriptOrURL, contents, isURL, success, status )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
entityID Uuid

Entity ID.

scriptOrURL string

Path.

contents string

Contents.

isURL boolean

Is a URL.

success boolean

Success.

status string

Status.

(static) executeOnScriptThread( function, typeopt )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Attributes Default Value Description
function function

Function.

type ConnectionType <optional>
2

Connection type.

(static) formatExecption( exception, inludeExtendeDetails ) → {string}
Returns: String.

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
exception object

Exception.

inludeExtendeDetails boolean

Include extended details.

(static) generateUUID( ) → {Uuid}
Returns: A new UUID.

Deprecated: This function is deprecated and will be removed. Use Uuid.generate instead.

(static) getContext( ) → {string}
Returns: The context that the script is running in:
  • "client": An Interface or avatar script.
  • "entity_client": A client entity script.
  • "entity_server": A server entity script.
  • "agent": An assignment client script.

Gets the context that the script is running in: Interface/avatar, client entity, server entity, or assignment client.

(static) getExternalPath( bucket, path ) → {string}
Returns: The URL of an external asset.

Gets the URL for an asset in an external resource bucket. (The location where the bucket is hosted may change over time but this method will return the asset's current URL.)

Parameters

Name Type Description
bucket Script.ResourceBucket

The external resource bucket that the asset is in.

path string

The path within the external resource bucket where the asset is located.

Normally, this should start with a path or filename to be appended to the bucket URL. Alternatively, it can be a relative path starting with ./ or ../, to navigate within the resource bucket's URL.

Examples

Report the URL of a default particle.

print(Script.getExternalPath(Script.ExternalPaths.Assets, "Bazaar/Assets/Textures/Defaults/Interface/default_particle.png"));

Report the root directory where the Overte assets are located.

print(Script.getExternalPath(Script.ExternalPaths.Assets, "."));
(static) getMemoryUsageStatistics( ) → {Script.MemoryUsageData}
Returns: Object containing statistics about memory usage.

Returns memory usage statistics data.

(static) include( filename, callbackopt )

Includes JavaScript from another file in the current script. If a callback is specified, the file is loaded and included asynchronously, otherwise it is included synchronously (i.e., script execution blocks while the file is included).

Parameters

Name Type Attributes Default Value Description
filename string

The URL of the script to include. It can be relative to the current script.

callback function <optional>
null

The function to call back when the script has been included. It can be either the name of a function or an in-line definition.

Example

Include a script file asynchronously.

// First file: scriptA.js
print("This is script A");

// Second file: scriptB.js
print("This is script B");
Script.include("scriptA.js", function () {
    print("Script A has been included");
});

// If you run scriptB.js you should see only scriptB.js in the running scripts list.
// And you should see the following output:
// This is script B
// This is script A
// Script A has been included
(static) include( filenames, callbackopt )

Includes JavaScript from other files in the current script. If a callback is specified, the files are loaded and included asynchronously, otherwise they are included synchronously (i.e., script execution blocks while the files are included).

Parameters

Name Type Attributes Default Value Description
filenames Array.<string>

The URLs of the scripts to include. Each can be relative to the current script.

callback function <optional>
null

The function to call back when the scripts have been included. It can be either the name of a function or an in-line definition.

(static) isAgentScript( ) → {boolean}
Returns: true if the script is running as an assignment client script, false if it isn't.

Checks whether the script is running as an assignment client script.

(static) isClientScript( ) → {boolean}
Returns: true if the script is running as an Interface or avatar script, false if it isn't.

Checks whether the script is running as an Interface or avatar script.

(static) isDebugMode( ) → {boolean}
Returns: true if the application was compiled as a debug build, false if it was compiled as a release build.

Checks whether the application was compiled as a debug build.

(static) isEntityClientScript( ) → {boolean}
Returns: true if the script is running as a client entity script, false if it isn't.

Checks whether the script is running as a client entity script.

(static) isEntityScriptRunning( entityID ) → {boolean}
Returns: true if the entity has an entity script running, false if it doesn't.

Checks whether an entity has an entity script running.

Parameters

Name Type Description
entityID Uuid

The ID of the entity.

(static) isEntityServerScript( ) → {boolean}
Returns: true if the script is running as a server entity script, false if it isn't.

Checks whether the script is running as a server entity script.

(static) load( filename )

Starts running another script in Interface, if it isn't already running. The script is not automatically loaded next time Interface starts.

Supported Script Types: Interface Scripts • Avatar Scripts

See also, ScriptDiscoveryService.loadScript.

Parameters

Name Type Description
filename string

The URL of the script to load. This can be relative to the current script's URL.

Example

Load a script from another script.

// First file: scriptA.js
print("This is script A");

// Second file: scriptB.js
print("This is script B");
Script.load("scriptA.js");

// If you run scriptB.js you should see both scripts in the Running Scripts dialog.
// And you should see the following output:
// This is script B
// This is script A
(static) loadEntityScript( entityID, script, forceRedownload )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
entityID Uuid

Entity ID.

script string

Script.

forceRedownload boolean

Force re-download.

(static) logBacktrace( title )

Prints out current backtrace to the log.

Parameters

Name Type Description
title string

Title added to the printed out backtrace.

(static) print( message )

Prints a message to the program log and emits Script.printedMessage.

Alternatively, you can use print or one of the console API methods.

Parameters

Name Type Description
message string

The message to print.

(static) registerValue( valueName, value )

registers a global object by name.

Parameters

Name Type Description
valueName string
value value
(static) removeEventHandler( entityID, eventName, handler )

Removes a function from the list of functions called when an entity event occurs on a particular entity.

See also, the Entities API.

Parameters

Name Type Description
entityID Uuid

The ID of the entity.

eventName Script.EntityEvent

The name of the entity event.

handler function

The name of the function to no longer call when the entity event occurs on the entity.

(static) requestGarbageCollection( )

Manually runs the JavaScript garbage collector which reclaims memory by disposing of objects that are no longer reachable.

(static) require( module ) → {object|array}
Returns: The value assigned to module.exports in the JavaScript file, or the value defined in the JSON file.

Provides access to methods or objects provided in an external JavaScript or JSON file. See https://docs.overte.org/script/js-tips.html for further details.

Parameters

Name Type Description
module string

The module to use. May be a JavaScript file, a JSON file, or the name of a system module such as "appUi" (i.e., the "appUi.js" system module JavaScript file).

(static) resetModuleCache( deleteScriptCacheopt )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Attributes Default Value Description
deleteScriptCache boolean <optional>
false

Delete script cache.

(static) resolvePath( path ) → {string}
Returns: The absolute path.

Resolves a relative path to an absolute path. The relative path is relative to the script's location.

Parameters

Name Type Description
path string

The relative path to resolve.

Examples

Report the directory and filename of the running script.

print(Script.resolvePath(""));

Report the directory of the running script.

print(Script.resolvePath("."));

Report the path to a file located relative to the running script.

print(Script.resolvePath("../assets/sounds/hello.wav"));
(static) resourcesPath( ) → {string}
Returns: The path to the resources directory for QML files.

Gets the path to the resources directory for QML files.

(static) setInterval( function, interval ) → {object}
Returns: A handle to the interval timer. This can be used in Script.clearInterval.

Calls a function repeatedly, at a set interval.

Parameters

Name Type Description
function function

The function to call. This can be either the name of a function or an in-line definition.

interval number

The interval at which to call the function, in ms.

Example

Print a message every second.

Script.setInterval(function () {
    print("Interval timer fired");
}, 1000);
(static) setTimeout( function, timeout ) → {object}
Returns: A handle to the timeout timer. This can be used in Script.clearTimeout.

Calls a function once, after a delay.

Parameters

Name Type Description
function function

The function to call. This can be either the name of a function or an in-line definition.

timeout number

The delay after which to call the function, in ms.

Example

Print a message once, after a second.

Script.setTimeout(function () {
    print("Timeout timer fired");
}, 1000);
(static) startCollectingObjectStatistics( )

Start collecting object statistics that can later be reported with Script.dumpHeapObjectStatistics().

(static) startProfiling( )

Starts collecting profiling data

(static) stop( marshalopt )

Stops and unloads the current script.

Warning: If an assignment client script, the script gets restarted after stopping.

Parameters

Name Type Attributes Default Value Description
marshal boolean <optional>
false

Marshal.

Deprecated: This parameter is deprecated and will be removed.

Example

Stop a script after 5s.

Script.setInterval(function () {
    print("Hello");
}, 1000);

Script.setTimeout(function () {
    Script.stop(true);
}, 5000);
(static) stopProfilingAndSave( )

Stops collecting profiling data and writes them to a timestamped CSV file in Logs directory.

Example

Collect profiling data from a script.

Script.startProfiling();
workFunc1();
Script.stopProfilingAndSave();

function workFunc1() {
    for (var i=0; i<100000; i++) {
        var vec1 = {x: i, y: i+1, z: i+2};
        var vec2 = {x: i+3, y: i+4, z: i+5};
        workFunc2(vec1, vec2);
    }
};
function workFunc2(vec1, vec2) {
    var cross = Vec3.cross(vec1, vec2);
    var dot = Vec3.dot(vec1, vec2);
};
(static) subscribeToServerEntityScriptMessages( entityIDopt )

After calling this function current script engine will start receiving server-side entity script messages through signals such as errorEntityMessage. This function can be invoked both from client-side entity scripts and from interface scripts.

Parameters

Name Type Attributes Description
entityID Uuid <optional>

The ID of the entity that requests entity server script messages. Only needs to be specified for entity scripts, and must not be specified for other types of scripts.

(static) unloadAllEntityScripts( blockingCallopt )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Attributes Default Value Description
blockingCall boolean <optional>
false

Wait for completion if call moved to another thread.

(static) unloadEntityScript( entityID, shouldRemoveFromMapopt )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Attributes Default Value Description
entityID Uuid

Entity ID.

shouldRemoveFromMap boolean <optional>
false

Should remove from map.

(static) unsubscribeFromServerEntityScriptMessages( entityIDopt )

Calling this function signalizes that current script doesn't require stop receiving server-side entity script messages through signals such as errorEntityMessage. This function can be invoked both from client-side entity scripts and from interface scripts.

Parameters

Name Type Attributes Description
entityID Uuid <optional>

The ID of the entity that requests entity server script messages. Only needs to be specified for entity scripts, and must not be specified for other types of scripts.

Signal Details

clearDebugWindow( )
Returns: Signal

Deprecated: This signal is deprecated and will be removed.

doneRunning( )
Returns: Signal

Triggered when the script has stopped.

entityScriptDetailsUpdated( )
Returns: Signal

Deprecated: This signal is deprecated and will be removed.

entityScriptPreloadFinished( entityID )
Returns: Signal

Triggered when the script starts for the user. See also, Entities.preload.

Supported Script Types: Client Entity Scripts • Server Entity Scripts

Parameters

Name Type Description
entityID Uuid

The ID of the entity that the script is running in.

Example

Get the ID of the entity that a client entity script is running in.

var entityScript = function () {
    this.entityID = Uuid.NULL;
};

Script.entityScriptPreloadFinished.connect(function (entityID) {
    this.entityID = entityID;
    print("Entity ID: " + this.entityID);
});

var entityID = Entities.addEntity({
    type: "Box",
    position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5 })),
    dimensions: { x: 0.5, y: 0.5, z: 0.5 },
    color: { red: 255, green: 0, blue: 0 },
    script: "(" + entityScript + ")",  // Could host the script on a Web server instead.
    lifetime: 300  // Delete after 5 minutes.
});
errorLoadingScript( filename )
Returns: Signal

Deprecated: This signal is deprecated and will be removed.

Parameters

Name Type Description
filename string

File name.

errorMessage( message, fileName, lineNumber, entityID, isServerScript )
Returns: Signal

Triggered when a client side entity script generates an error, console.error or console.exception is called, or console.assert is called and fails.

Parameters

Name Type Description
message string

The error message.

fileName string

Name of the file in which message was generated. Empty string when no file name is available.

lineNumber number

Number of the line on which message was generated. -1 if there line number is not available.

entityID Uuid

Entity ID.

isServerScript boolean

true if entity script is server-side, false if it is client-side.

errorMessage( message, scriptName )
Returns: Signal

Triggered when the script generates an error, console.error or console.exception is called, or console.assert is called and fails.

Parameters

Name Type Description
message string

The error message.

scriptName string

The name of the script that generated the error message.

infoMessage( message, fileName, lineNumber, entityID, isServerScript )
Returns: Signal

Triggered when a client side entity script generates an information message or console.info is called.

Parameters

Name Type Description
message string

The information message.

fileName string

Name of the file in which message was generated. Empty string when no file name is available.

lineNumber number

Number of the line on which message was generated. -1 if there line number is not available.

entityID Uuid

Entity ID.

isServerScript boolean

true if entity script is server-side, false if it is client-side.

infoMessage( message, scriptName )
Returns: Signal

Triggered when the script generates an information message or console.info is called.

Parameters

Name Type Description
message string

The information message.

scriptName string

The name of the script that generated the information message.

loadScript( scriptName, isUserLoaded )
Returns: Signal

Deprecated: This signal is deprecated and will be removed.

Parameters

Name Type Description
scriptName string

Script name.

isUserLoaded boolean

Is user loaded.

printedMessage( message, fileName, lineNumber, entityID, isServerScript )
Returns: Signal

Triggered when a client side entity script prints a message to the program log via print, Script.print, console.log, console.debug, console.group, console.groupEnd, console.time, or console.timeEnd.

Parameters

Name Type Description
message string

The message.

fileName string

Name of the file in which message was generated. Empty string when no file name is available.

lineNumber number

Number of the line on which message was generated. -1 if there line number is not available.

entityID Uuid

Entity ID.

isServerScript boolean

true if entity script is server-side, false if it is client-side.

printedMessage( message, scriptName )
Returns: Signal

Triggered when the script prints a message to the program log via print, Script.print, console.log, console.debug, console.group, console.groupEnd, console.time, or console.timeEnd.

Parameters

Name Type Description
message string

The message.

scriptName string

The name of the script that generated the message.

reloadScript( scriptName, isUserLoaded )
Returns: Signal

Deprecated: This signal is deprecated and will be removed.

Parameters

Name Type Description
scriptName string

Script name.

isUserLoaded boolean

Is user loaded.

runningStateChanged( )
Returns: Signal

Triggered when the running state of the script changes, e.g., from running to stopping.

scriptEnding( )
Returns: Signal

Triggered when the script is stopping.

Example

Report when a script is stopping.

print("Script started");

Script.scriptEnding.connect(function () {
    print("Script ending");
});

Script.setTimeout(function () {
    print("Stopping script");
    Script.stop();
}, 1000);
scriptLoaded( filename )
Returns: Signal

Deprecated: This signal is deprecated and will be removed.

Parameters

Name Type Description
filename string

File name.

unhandledException( exception )
Returns: Signal

Triggered when a script generates an unhandled exception.

Parameters

Name Type Description
exception object

The details of the exception.

Example

Report the details of an unhandled exception.

Script.unhandledException.connect(function (exception) {
    print("Unhandled exception: " + JSON.stringify(exception));
});
var properties = JSON.parse("{ x: 1"); // Invalid JSON string.
update( deltaTime )
Returns: Signal

Triggered frequently at a system-determined interval.

Parameters

Name Type Description
deltaTime number

The time since the last update, in s.

Example

Report script update intervals.

Script.update.connect(function (deltaTime) {
    print("Update: " + deltaTime);
});
warningMessage( message, fileName, lineNumber, entityID, isServerScript )
Returns: Signal

Triggered when a client side entity script generates a warning or console.warn is called.

Parameters

Name Type Description
message string

The warning message.

fileName string

Name of the file in which message was generated. Empty string when no file name is available.

lineNumber number

Number of the line on which message was generated. -1 if there line number is not available.

entityID Uuid

Entity ID.

isServerScript boolean

true if entity script is server-side, false if it is client-side.

warningMessage( message, scriptName )
Returns: Signal

Triggered when the script generates a warning or console.warn is called.

Parameters

Name Type Description
message string

The warning message.

scriptName string

The name of the script that generated the warning message.