Subscribing to Events

 

void SubscribeToEvent(event: string, componentName: string, componentTypeName: string, callback: string);

or

void SubscribeToEvent(event: string, componentName: string, componentTypeName: string, callback: object);

Subscribes to an event callback exposed by a component

Note: Some events do not support multiple subscription. See more in component.

Parameters

Parameter Name Type Description
event String The name of the event to subscribe to
componentName String The name of the component that will invoke the event
componentTypeName String The type of the component. e.g. 'PE Sensor'
callback Object Can be a string (The name of the callback function) or the callback function itself

Return Value - void.

function OnSimulationStart() {

    SubscribeToEvent("OnProductBlocking", "PESensor1", "PE Sensor", OnProductBlocking_PESensor1);
}

				
function OnProductBlocking_PESensor1(sender, product) {

    MoveProduct(product, "Conveyor2", 0.3);
} 
			

void UnSubscribeToEvent(event: string, componentName: string, componentTypeName: string, callback: string);

or

void UnSubscribeToEvent(event: string, componentName: string, componentTypeName: string, callback: object);

Unsubscribe to an event callback from a previously subscribed event

Parameters

Parameter Name Type Description
event String The name of the event to subscribe to
componentName String The name of the component that will invoke the event
componentTypeName String The type of the component. e.g. 'Cross Belt Sorter'
callback Object Can be a string (The name of the callback function) or the callback function itself

Return Value - void.

function SubscribePESensor1()
{
	SubscribeToEvent('OnProductBlocking', 'PESensor1', 'PE Sensor', OnProductBlocking_PESensor1);
}

function UnsubscribePESensor1()
{
	UnSubscribeToEvent('OnProductBlocking', 'PESensor1', 'PE Sensor', OnProductBlocking_PESensor1);
}
			

void SubscribeAll(event: string, componentTypeName: string, callbackName: string);

Subscribes to an event callback for all the instances of a given type

Note: Some events do not support multiple subscription. See more in component.

Parameters

Parameter Name Type Description
event String The name of the event to subscribe to
componentTypeName String The type name of the components that will invoke the events
callbackName String The name of the callback function

Return Value - void.

void UnSubscribeAll(event: string, componentTypeName: string, callbackName: string);

Unsubscribe to an event callback for all the instances of a given type

Parameters

Parameter Name Type Description
event String The name of the event to subscribe to
componentTypeName String The type name of the components that will invoke the events
callbackName String The name of the callback function

Return Value - void.

void Subscribe(event: string, componentName: string, callbackName: string); Deprecated, See "void SubscribeToEvent(event: string, componentName: string, componentTypeName: string, callback: string);"

Subscribes to an event callback exposed by a component

Parameters

Parameter Name Type Description
event String The name of the event to subscribe to
componentName String The name of the component that will invoke the event
callbackName String The name of the callback function

Return Value - void.

void UnSubscribe(event: string, componentName: string, callbackName: string);Deprecated, See "void UnSubscribeToEvent(event: string, componentName: string, componentTypeName: string, callback: string);"

Unsubscribe to an event callback from a previously subscribed event

Parameters

Parameter Name Type Description
event String The name of the event to subscribe to
componentName String The name of the component that will invoke the event
callbackName String The name of the callback function

Return Value - void.

Example