API Reference

Class List

pc.ScriptRegistry

Container for all Script Types that are available to this application

Summary

Methods

addAdd ScriptType to registry.
getGet ScriptType by name.
hasCheck if a ScriptType with the specified name is in the registry.
listGet list of all ScriptTypes from registry.
removeRemove ScriptType.

Details

Constructor

ScriptRegistry(app)

Create an instance of a pc.ScriptRegistry. Note: PlayCanvas scripts can access the Script Registry from inside the application with pc.Application#scripts pc.ADDRESS_REPEAT.

Parameters

apppc.ApplicationApplication to attach registry to.

Methods

add(scriptType)

Add ScriptType to registry. Note: when pc.createScript is called, it will add the ScriptType to the registry automatically. If a script already exists in registry, and the new script has a `swap` method defined, it will perform code hot swapping automatically in async manner.

var PlayerController = pc.createScript('playerController');
// playerController Script Type will be added to pc.ScriptRegistry automatically
app.scripts.has('playerController') === true; // true

Parameters

scriptTypeScriptTypeScript Type that is created using pc.createScript

Returns

Boolean True if added for the first time or false if script already exists

get(name)

Get ScriptType by name.

var PlayerController = app.scripts.get('playerController');

Parameters

nameStringName of a ScriptType.

Returns

ScriptType The Script Type if it exists in the registry or null otherwise.

has(name)

Check if a ScriptType with the specified name is in the registry.

if (app.scripts.has('playerController')) {
    // playerController is in pc.ScriptRegistry
}

Parameters

nameStringName of a ScriptType

Returns

Boolean True if ScriptType is in registry

list()

Get list of all ScriptTypes from registry.

// logs array of all Script Type names available in registry
console.log(app.scripts.list().map(function(o) {
    return o.name;
}));

Returns

ScriptType[] list of all ScriptTypes in registry

remove(name)

Remove ScriptType.

app.scripts.remove('playerController');

Parameters

nameStringName of a ScriptType to remove

Returns

Boolean True if removed or False if already not in registry