how to make value persistent
Posted: May 23rd, 2008, 8:21 am
Hi! I made an expression (applied on timeRemap of a sequence) that displays a specific frame of a sequence based on the position of a guide layer. If the guide layer (called "temoin" in the following code) is over a certain reference layer (in "targetComp" in the code), it then displays a specific frame based on the reference layer index. The problem is that by default it always resets to 1. I would like it to keep the last valid value. Is there a a way to achieve this?
Thanks,
Louis
Thanks,
Louis
Code: Select all
targetComp = comp("as_claydog");
temoin = thisComp.layer("temoin");
curClosestIndex = null;
previousFrame = timeRemap;
for (var i = 1; i <= targetComp.numLayers; i++)
{
layerPos = targetComp.layer(i).position;
layerWidth = targetComp.layer(i).width/2*(targetComp.layer(i).scale[0]/100);
layerHeight= targetComp.layer(i).height/2*(targetComp.layer(i).scale[1]/100);
minX = layerPos[0] - (layerWidth);
maxX = layerPos[0] + (layerWidth);
minY = layerPos[1] - (layerHeight);
maxY = layerPos[1] + (layerHeight);
curPos = temoin.position;
if ( curPos[0] > minX && curPos[0] < maxX)
{
if ( curPos[1] > minY && curPos[1] < maxY)
{
curClosestIndex = i;
}
}
}
if (curClosestIndex != null)
{
frames = curClosestIndex -1;
fps = 1.0 / thisComp.frameDuration;
timeRemap = framesToTime(frames, fps );
} else {
timeRemap = previousFrame;
}