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", }

  • 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 = - startTime; //If more than 30 seconds since the chain began repeating, terminate clip repeats if (elapsedTime > 30000) $context.currentChain.endRepeat();