User Tools

Site Tools

Callback - Element Current Value Changed, Update Renderer Property


The script on this page is included by a script embedded within, and executed by, a DzCallBack that is connected to the currentValueChanged() signal on a DzProperty, which resides on a DzElement in the scene. Several variables used in this script are assumed to be defined in the script that includes this script.

The purpose of this script is to find a (predefined) target property associated with a DzRenderer, compare the values of that property with the value of the property that invoked the callback, and either update the value of the target property (if it does not already match) or break the infinite loop that is created by causing the currentValueChanged() signal to be emitted in sequential succession.

See Also: Element Post-Load Create Callbacks

API Areas of Interest


// Define an anonymous function;
// limits the scope of variables
	// 'CallBack' is a global transient variable, available when
	// this script is executed by a DzCallBack
	// If we did not find the 'CallBack' global transient;
	// this script was executed outside the context of a DzCallBack	
	if( typeof( CallBack ) == "undefined" ){
		// We are done...
	// Get the object that prompted the callback
	var oSender = CallBack.getSender();
	// If we do not have a sender or the sender is not a property
	if( !oSender || !oSender.inherits( "DzProperty" ) ){
		// We are done...
	// oScript, sBasePath, and sProperty are assumed to be defined in the script
	// that includes this script; i.e., the CallBack
	// created in Callbacks_Element_Post_Load_Create.ds*
	// Get the path of the FindProperty script. Doing it this way, we can debug
	// with an ascii file and ship a binary [encrypted] file with the same
	// name... without having to update the contents of the script or manually
	// handle the file extensions.
	var sFindPropertyPath = oScript.getScriptFile( "%1/FindProperty".arg( sBasePath ) );
	// If the script was not found
	if( sFindPropertyPath.isEmpty() ){
		// We are done...
	// Include the FindProperty script
	include( sFindPropertyPath );
	// Find the property
	var oProperty = findRendererProperty( "DzIrayRenderer", "", sProperty, false, false );
	// If the property was not found
	if( !oProperty ){
		// We are done...
	// Get the value of the sender
	var vValue = oSender.getValue();
	// If the value of the target is the same as the source
	if( oProperty.getValue() != vValue ){
		// Update the value of the target with the sender's value
		oProperty.setValue( vValue );
// Finalize the function and invoke