API Reference

Class List

ScriptType

Represents the type of a script. It is returned by pc.createScript. Also referred to as Script Type.
The type is to be extended using its JavaScript prototype. There is a list of methods that will be executed by the engine on instances of this type, such as:

initialize and postInitialize - are called if defined when script is about to run for the first time - postInitialize will run after all initialize methods are executed in the same tick or enabling chain of actions.
update and postUpdate - methods are called if defined for enabled (running state) scripts on each tick.
swap - This method will be called when a ScriptType that already exists in the registry gets redefined. If the new ScriptType has a `swap` method in its prototype, then it will be executed to perform hot-reload at runtime.

Summary

Static Properties

attributesThe interface to define attributes for Script Types.[read only]

Static Methods

extendShorthand function to extend Script Type prototype with list of methods.

Properties

appThe pc.Application that the instance of this type belongs to.
enabledTrue if the instance of this type is in running state.
entityThe pc.Entity that the instance of this type belongs to.

Events

attr:[name]Fired when a specific script attribute has been changed
attrFired when any script attribute has been changed
destroyFired when a script instance is destroyed and removed from component
disableFired when a script instance becomes disabled
enableFired when a script instance becomes enabled
errorFired when a script instance had an exception.
stateFired when a script instance changes state to enabled or disabled

Details

Static Properties

attributesThe interface to define attributes for Script Types. Refer to pc.ScriptAttributes[read only]

Static Methods

extend(methods)

Shorthand function to extend Script Type prototype with list of methods.

var PlayerController = pc.createScript('playerController');

PlayerController.extend({
    initialize: function() {
        // called once on initialize
    },
    update: function(dt) {
        // called each tick
    }
})

Parameters

methodsObjectObject with methods, where key - is name of method, and value - is function.

Constructor

ScriptType()

Properties

pc.Applicationapp

The pc.Application that the instance of this type belongs to.

Booleanenabled

True if the instance of this type is in running state. False when script is not running, because the Entity or any of its parents are disabled or the Script Component is disabled or the Script Instance is disabled. When disabled no update methods will be called on each tick. initialize and postInitialize methods will run once when the script instance is in `enabled` state during app tick.

pc.Entityentity

The pc.Entity that the instance of this type belongs to.

Events

attr:[name]

Fired when a specific script attribute has been changed

Parameters

valueObjectNew value
valueOldObjectOld value

attr

Fired when any script attribute has been changed

Parameters

nameStringName of attribute
valueObjectNew value
valueOldObjectOld value

destroy

Fired when a script instance is destroyed and removed from component

disable

Fired when a script instance becomes disabled

enable

Fired when a script instance becomes enabled

error

Fired when a script instance had an exception. The script instance will be automatically disabled.

Parameters

errErrorNative JavaScript Error object with details of error
methodStringThe method of the script instance that the exception originated from.

state

Fired when a script instance changes state to enabled or disabled

Parameters

enabledBooleanTrue if now enabled, False if disabled