Description
Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts
TheScript
API provides facilities for working with scripts.Properties
Name | Type | Summary |
---|---|---|
context | string |
The context that the script is running in:
|
type | string |
The type of script that is running:
|
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. |
beginProfileRange
|
None |
Starts timing a section of code in order to send usage data about it to Vircadia. Shouldn't be used outside of the standard scripts. |
callAnimationStateHandler
|
None |
Deprecated: This function is deprecated and will be removed. |
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. |
endProfileRange
|
None |
Finishes timing a section of code in order to send usage data about it to Vircadia. Shouldn't be used outside of the standard scripts. |
entityScriptContentAvailable
|
None |
Deprecated: This function is deprecated and will be removed. |
evaluate
|
object |
Deprecated: This function is deprecated and will be removed. |
evaluateInClosure
|
object |
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.) |
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. |
lintScript
|
object |
Deprecated: This function is deprecated and will be removed. |
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. |
makeError
|
object |
Deprecated: This function is deprecated and will be removed. |
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. |
registerEnum
|
None |
Deprecated: This function is deprecated and will be removed. |
registerFunction
|
None |
Deprecated: This function is deprecated and will be removed. |
registerFunction
|
None |
Deprecated: This function is deprecated and will be removed. |
registerGetterSetter
|
None |
Deprecated: This function is deprecated and will be removed. |
registerGlobalObject
|
None |
Deprecated: This function is deprecated and will be removed. |
registerValue
|
None |
Deprecated: This function is deprecated and will be removed. |
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.vircadia.com/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. |
stop
|
None |
Stops and unloads the current script. Warning: If an assignment client script, the script gets restarted after stopping. |
unloadAllEntityScripts
|
None |
Deprecated: This function is deprecated and will be removed. |
unloadEntityScript
|
None |
Deprecated: This function is deprecated and will be removed. |
updateMemoryCost
|
None |
Deprecated: This function is deprecated and will be removed. |
Signals
Name | Summary |
---|---|
cleanupMenuItem
|
Deprecated: This signal is deprecated and will be removed. |
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 the script generates an error, console.error or console.exception is called, or console.assert is called and fails. |
finished
|
Deprecated: This signal is deprecated and will be removed. |
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 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. |
signalHandlerException
|
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 the script generates a warning or console.warn is called. |
Type Definitions
ResourceBucket Type: number |
|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
An external resource bucket.
|
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 Vircadia's "Assets" bucket. This should ease the transition from High Fidelity and ensure a clean separation. Properties
|
collisionEventCallback( entityA, entityB, collisionEvent )
Type: function |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Called when a collision event occurs on an entity as registered with Script.addEventHandler. Parameters
|
entityEventCallback( entityID )
Type: function |
||||||
---|---|---|---|---|---|---|
Called when an entity event occurs on an entity as registered with Script.addEventHandler. Parameters
|
pointerEventCallback( entityID, pointerEvent )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when a pointer event occurs on an entity as registered with Script.addEventHandler. Parameters
|
Method Details
(static) _requireResolve( module, relativeToopt ) → {string}
Returns: Result. |
|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(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
Example
|
(static) beginProfileRange( label ) | ||||||
---|---|---|---|---|---|---|
Starts timing a section of code in order to send usage data about it to Vircadia. Shouldn't be used outside of the standard scripts. Parameters
|
(static) callAnimationStateHandler( callback, parameters, names, useNames, resultHandler ) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) callEntityScriptMethod( entityID, methodName, parametersopt, remoteCallerIDopt ) | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Calls a method in an entity script. Parameters
|
(static) callEntityScriptMethod( entityID, methodName, event ) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Calls a method in an entity script. Deprecated: This function is deprecated and will be removed. Parameters
|
(static) callEntityScriptMethod( entityID, methodName, otherID, collision ) | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Calls a method in an entity script. Deprecated: This function is deprecated and will be removed. Parameters
|
(static) clearInterval( timer ) | ||||||
---|---|---|---|---|---|---|
Stops an interval timer set by setInterval. Parameters
Example
|
(static) clearTimeout( timer ) | ||||||
---|---|---|---|---|---|---|
Stops a timeout timer set by setTimeout. Parameters
Example
|
(static) endProfileRange( label ) | ||||||
---|---|---|---|---|---|---|
Finishes timing a section of code in order to send usage data about it to Vircadia. Shouldn't be used outside of the standard scripts. Parameters
|
(static) entityScriptContentAvailable( entityID, scriptOrURL, contents, isURL, success, status ) | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) evaluate( program, filename, lineNumberopt ) → {object}
Returns: Object. |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) evaluateInClosure( locals, program ) → {object}
Returns: Object. |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) executeOnScriptThread( function, typeopt ) | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) formatExecption( exception, inludeExtendeDetails ) → {string}
Returns: String. |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(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:
|
---|
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
Examples
|
(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
Example
|
(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
|
(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
|
(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) lintScript( sourceCode, fileName, lineNumberopt ) → {object}
Returns: Object. |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(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
Example
|
(static) loadEntityScript( entityID, script, forceRedownload ) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) makeError( otheropt, typeopt ) → {object}
Returns: Object. |
|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(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
|
(static) registerEnum( name, enum ) | |||||||||
---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) registerFunction( name, function, numArgumentsopt ) | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) registerFunction( parent, name, function, numArgumentsopt ) | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) registerGetterSetter( name, getter, setter, parentopt ) | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) registerGlobalObject( name, object ) | |||||||||
---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) registerValue( name, value ) | |||||||||
---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(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
|
(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.vircadia.com/script/js-tips.html for further details. Parameters
|
(static) resetModuleCache( deleteScriptCacheopt ) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(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
Examples
|
(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
Example
|
(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
Example
|
(static) stop( marshalopt ) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Stops and unloads the current script. Warning: If an assignment client script, the script gets restarted after stopping. Parameters
Example
|
(static) unloadAllEntityScripts( blockingCallopt ) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) unloadEntityScript( entityID, shouldRemoveFromMapopt ) | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
(static) updateMemoryCost( deltaSize ) | ||||||
---|---|---|---|---|---|---|
Deprecated: This function is deprecated and will be removed. Parameters
|
Signal Details
cleanupMenuItem(
menuItem
)
Returns: Signal |
||||||
---|---|---|---|---|---|---|
Deprecated: This signal is deprecated and will be removed. Parameters
|
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
Example
|
errorLoadingScript(
filename
)
Returns: Signal |
||||||
---|---|---|---|---|---|---|
Deprecated: This signal is deprecated and will be removed. Parameters
|
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
|
finished(
filename,
engine
)
Returns: Signal |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Deprecated: This signal is deprecated and will be removed. Parameters
|
infoMessage(
message,
scriptName
)
Returns: Signal |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Triggered when the script generates an information message or console.info is called. Parameters
|
loadScript(
scriptName,
isUserLoaded
)
Returns: Signal |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Deprecated: This signal is deprecated and will be removed. Parameters
|
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
|
reloadScript(
scriptName,
isUserLoaded
)
Returns: Signal |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Deprecated: This signal is deprecated and will be removed. Parameters
|
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
|
scriptLoaded(
filename
)
Returns: Signal |
||||||
---|---|---|---|---|---|---|
Deprecated: This signal is deprecated and will be removed. Parameters
|
signalHandlerException(
exception
)
Returns: Signal |
||||||
---|---|---|---|---|---|---|
Deprecated: This signal is deprecated and will be removed. Parameters
|
unhandledException(
exception
)
Returns: Signal |
||||||
---|---|---|---|---|---|---|
Triggered when a script generates an unhandled exception. Parameters
Example
|
update(
deltaTime
)
Returns: Signal |
||||||
---|---|---|---|---|---|---|
Triggered frequently at a system-determined interval. Parameters
Example
|
warningMessage(
message,
scriptName
)
Returns: Signal |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Triggered when the script generates a warning or console.warn is called. Parameters
|