Script

Description

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

Properties

Name Type Summary
context string

Methods

Name Return Value Summary
_requireResolve string
addEventHandler None
beginProfileRange None
callAnimationStateHandler None

Deprecated: This function is deprecated and will be removed.

callEntityScriptMethod None
callEntityScriptMethod None
callEntityScriptMethod None
clearInterval None Stop an interval timer set by setInterval.
clearTimeout None Clear a timeout timer set by setTimeout.
endProfileRange None
entityScriptContentAvailable None
evaluate object
evaluateInClosure object
executeOnScriptThread None
generateUUID Uuid
getContext string
include None Include 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 Include 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
isClientScript boolean
isDebugMode boolean
isEntityClientScript boolean
isEntityScriptRunning boolean
isEntityServerScript boolean
load None Start a new Interface or entity script.
loadEntityScript None
print None
registerFunction None
registerFunction None
registerGetterSetter None
registerGlobalObject None
registerValue None
removeEventHandler None
requestGarbageCollection None
require None
resetModuleCache None
resolvePath string Resolve a relative path to an absolute path.
resourcesPath string
setInterval object Call a function at a set interval.
setTimeout object Call a function after a delay.
stop None Stop the current script.
unloadAllEntityScripts None
unloadEntityScript None
updateMemoryCost None

Signals

Name Summary
cleanupMenuItem
clearDebugWindow
doneRunning
entityScriptDetailsUpdated
entityScriptPreloadFinished
errorLoadingScript
errorMessage
finished
infoMessage
loadScript
printedMessage
reloadScript
runningStateChanged
scriptEnding Triggered when the script is ending.
scriptLoaded
update Triggered regularly at a system-determined frequency.
warningMessage

Method Details

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

Parameters

Name Type Attributes Default Value Description
module string
relativeTo string <optional>
""
(static) addEventHandler( entityID, eventName, handler )

Parameters

Name Type Description
entityID Uuid
eventName string
handler function
(static) beginProfileRange( label )

Parameters

Name Type Description
label string
(static) callAnimationStateHandler( callback, parameters, names, useNames, resultHandler )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
callback function Callback.
parameters object Parameters.
names Array.<string> Names.
useNames boolean Use names.
resultHandler function Result handler.
(static) callEntityScriptMethod( entityID, methodName, otherID, collision )

Parameters

Name Type Description
entityID Uuid
methodName string
otherID Uuid
collision Collision
(static) callEntityScriptMethod( entityID, methodName, parameters, remoteCallerIDopt )

Parameters

Name Type Attributes Default Value Description
entityID Uuid
methodName string
parameters Array.<string>
remoteCallerID Uuid <optional>
Uuid.NULL
(static) callEntityScriptMethod( entityID, methodName, event )

Parameters

Name Type Description
entityID Uuid
methodName string
event PointerEvent
(static) clearInterval( timer )

Stop an interval timer set by setInterval.

Parameters

Name Type Description
timer object The interval timer to clear.
Example

Stop an interval timer.

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

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

Clear a timeout timer set by setTimeout.

Parameters

Name Type Description
timer object The timeout timer to clear.
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) endProfileRange( label )

Parameters

Name Type Description
label string
(static) entityScriptContentAvailable( entityID, scriptOrURL, contents, isURL, success, status )

Parameters

Name Type Description
entityID Uuid
scriptOrURL string
contents string
isURL boolean
success boolean
status string
(static) evaluate( program, filename, lineNumberopt ) → {object}
Returns: object

Parameters

Name Type Attributes Default Value Description
program string
filename string
lineNumber number <optional>
-1
(static) evaluateInClosure( locals, program ) → {object}
Returns: object

Parameters

Name Type Description
locals object
program object
(static) executeOnScriptThread( function, typeopt )

Parameters

Name Type Attributes Default Value Description
function object
type ConnectionType <optional>
2
(static) generateUUID( ) → {Uuid}
Returns: Uuid

(static) getContext( ) → {string}
Returns: string

(static) include( filename, callbackopt )

Include 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. Can be relative to the current script.
callback function <optional>
null The function to call back when the script has been included. Can be an in-line function or the name of a function.
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 )

Include 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. Can be an in-line function or the name of a function.
(static) isAgentScript( ) → {boolean}
Returns: boolean

(static) isClientScript( ) → {boolean}
Returns: boolean

(static) isDebugMode( ) → {boolean}
Returns: boolean

(static) isEntityClientScript( ) → {boolean}
Returns: boolean

(static) isEntityScriptRunning( entityID ) → {boolean}
Returns: boolean

Parameters

Name Type Description
entityID Uuid
(static) isEntityServerScript( ) → {boolean}
Returns: boolean

(static) load( filename )

Start a new Interface or entity script.

Parameters

Name Type Description
filename string The URL of the script to load. Can be relative to the current script.
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 list.
// And you should see the following output:
// This is script B
// This is script A
(static) loadEntityScript( entityID, script, forceRedownload )

Parameters

Name Type Description
entityID Uuid
script string
forceRedownload boolean
(static) print( message )

Parameters

Name Type Description
message string
(static) registerFunction( name, function, numArgumentsopt )

Parameters

Name Type Attributes Default Value Description
name string
function object
numArguments number <optional>
-1
(static) registerFunction( parent, name, function, numArgumentsopt )

Parameters

Name Type Attributes Default Value Description
parent string
name string
function object
numArguments number <optional>
-1
(static) registerGetterSetter( name, getter, setter, parentopt )

Parameters

Name Type Attributes Default Value Description
name string
getter object
setter object
parent string <optional>
""
(static) registerGlobalObject( name, object )

Parameters

Name Type Description
name string
object object
(static) registerValue( name, value )

Parameters

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

Parameters

Name Type Description
entityID Uuid
eventName string
handler function
(static) requestGarbageCollection( )

(static) require( module )

Parameters

Name Type Description
module string
(static) resetModuleCache( deleteScriptCacheopt )

Parameters

Name Type Attributes Default Value Description
deleteScriptCache boolean <optional>
false
(static) resolvePath( path ) → {string}
Returns: The absolute path.

Resolve a relative path to an absolute path.

Parameters

Name Type Description
path string The relative path to resolve.
(static) resourcesPath( ) → {string}
Returns: string

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

Call a function at a set interval.

Parameters

Name Type Description
function function The function to call. Can be an in-line function or the name of a function.
interval number The interval at which to call the function, in ms.
Example

Print a message every second.

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

Call a function after a delay.

Parameters

Name Type Description
function function The function to call. Can be an in-line function or the name of a function.
timeout number The delay after which to call the function, in ms.
Example

Print a message after a second.

Script.setTimeout(function () {
    print("Timer fired");
}, 1000);
(static) stop( marshalopt )

Stop the current script.

Parameters

Name Type Attributes Default Value Description
marshal boolean <optional>
false
(static) unloadAllEntityScripts( )

(static) unloadEntityScript( entityID, shouldRemoveFromMapopt )

Parameters

Name Type Attributes Default Value Description
entityID Uuid
shouldRemoveFromMap boolean <optional>
false
(static) updateMemoryCost( deltaSize )

Parameters

Name Type Description
deltaSize number

Signal Details

cleanupMenuItem( menuItem )
Returns: Signal

 

Parameters

Name Type Description
menuItem string
clearDebugWindow( )
Returns: Signal

 

doneRunning( )
Returns: Signal

 

entityScriptDetailsUpdated( )
Returns: Signal

 

entityScriptPreloadFinished( )
Returns: Signal

 

errorLoadingScript( filename )
Returns: Signal

 

Parameters

Name Type Description
filename string
errorMessage( message, scriptName )
Returns: Signal

 

Parameters

Name Type Description
message string
scriptName string
finished( filename, engine )
Returns: Signal

 

Parameters

Name Type Description
filename string
engine object
infoMessage( message, scriptName )
Returns: Signal

 

Parameters

Name Type Description
message string
scriptName string
loadScript( scriptName, isUserLoaded )
Returns: Signal

 

Parameters

Name Type Description
scriptName string
isUserLoaded boolean
printedMessage( message, scriptName )
Returns: Signal

 

Parameters

Name Type Description
message string
scriptName string
reloadScript( scriptName, isUserLoaded )
Returns: Signal

 

Parameters

Name Type Description
scriptName string
isUserLoaded boolean
runningStateChanged( )
Returns: Signal

 

scriptEnding( )
Returns: Signal

Triggered when the script is ending.

Example

Connect to the scriptEnding signal.

print("Script started");

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

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

 

Parameters

Name Type Description
filename string
update( deltaTime )
Returns: Signal

Triggered regularly at a system-determined frequency.

Parameters

Name Type Description
deltaTime number The time since the last update, in s.
warningMessage( message, scriptName )
Returns: Signal

 

Parameters

Name Type Description
message string
scriptName string