Setting Sequential Repeat on Chains and Clips

Document created by Chris Sommerstad Employee on Jul 21, 2017
Version 1Show Document
  • View in full screen mode

Repeat a Chain Sequentially for a Set Amount of Time

 

Chains can be repeated sequentially for a certain length of time by the placement of two scripts within the chain itself.

Any number of Messages or other Clip Elements can be placed between the two Scripts.

  • The first script, Record start time, is placed at the beginning of the chain and records the starting time of the first repeat of the chain in a Chain Custom Property.

//Is this the first repeat of this chain?
if ($context.currentChainIndex=0)
{
//This is the first repeat of this chain.

//Get the Chain's property list
var propList = $context.currentChain.propertyList;

//Create the StartTime property, ignoring any errors
//if the list already exists.

try
{ 
proplist.createProperty("Start Time")
}
catch (e)
{
}

//Set the property value to the time of this, the first
//repeat. (in milliseconds since January 1, 1970
propList.setPropertyValue("Start Time", Date.now())
}

  • The second script, Check elapsed time, is placed at the end of the chain and measures the elapsed time at the end of each repeat. If the desired amount of time has passed, it causes the chain to stop repeating. The chain is set to repeat for a very large number of repeats so that it will repeat forever until the second Script stops it.

Alternatively, a number could be set as the maximum. For example, if you wanted to repeat for “n” times or until “m” seconds have passed, whichever comes first.

//Get the startTime that was set by the "Record start time" script, from the
// chain property that it was placed into.
var startTime = $context.currentChain.propertyList.getPropertyValue("Start Time");

//Come the elapsed time since repeating started (in milliseconds)
var elapsedTime = Date.now() - startTime;

//If more than 30 seconds since the chain began repeating, terminate clip repeats
if (elapsedTime > 30000)
$context.currentChain.endRepeat();

Repeat a Clip Sequentially for a Set Amount of Time

 

Clips can be repeated sequentially for certain length of time by the placement of two scripts within the clip itself. The first Script is placed at the beginning of the Clip, and records the starting time of the first repeat of the Clip in a Clip Custom Property. The second Script is placed at the end of the Clip, and measures the elapsed time at the end of each repeat. If the desired amount of time has passed, it causes the Clip to stop repeating.

The Clip is set to repeat for a very large number of repeats, so that it will repeat forever until the second Script stops it. Alternatively, a number could be set as the maximum, for example if you wanted to repeat for "n times or until m seconds have passed, whichever comes first".

Note that any number of Messages or other Clip Elements could be between the two Scripts. This example contains a Delay simply to make the example not generate too much data.

 

The composition contains a test clip with a large number of repeats.

The Record start time script source is presented here.

// Is this the first repeat of this Clip?
if ($context.currentClipIndex == 0)
{
// This is the first repeat of this clip.

// Get the Clip's property list.
var propList = $context.currentClip.propertyList;

// Create the "StartTime" property, ignoring any errors
// if the property already exists.
try
{
propList.createProperty("StartTime");
}
catch (e)
{
}

// Set the property value to the time of this, the first
// repeat (in milliseconds since January 1, 1970).
propList.setPropertyValue("StartTime", Date.now());
}

The Check elapsed time script source is presented here.

// Get the startTime that was set by the "Record start time" Script, from the
// Clip property that it was placed into.
var startTime = $context.currentClip.propertyList.getPropertyValue("StartTime");

// Compute the elapsed time that has passed since repeating started (in milliseconds).
var elapsedTime = Date.now() - startTime;

// If it has been more than 30 seconds since the Clip started, terminate the repeating
// of this Clip.
if (elapsedTime > 30000) 
$context.currentClip.endRepeat();

Attachments

    Outcomes