Here you go:
chk = thisComp.layer("Animation Controller").effect("Run PBar Animation")(1);
prevAnimations = 0 - thisComp.frameDuration;
for (i = 0; i <= timeToFrames(time); i++)
{
if (chk.valueAtTime(framesToTime(i)) == 1)
{
prevAnimations += thisComp.frameDuration;
} else
{
continue;
}
}
prevAnimations;
You need to have a layer "Animation Controller" with a checkbox "Run PBar Animation" to turn on/off the animation. The checkbox should be the first control in the layer effects stack. If not, alter the number at the end of the first line or pigwhip the checkbox into this line.
Also, you need a pre-comp with time remap enabled. This code goes to the time remap proberty of this pre-comp.
Inside this pre-comp, you just create your progress bar animation with keyframes. I used a shape layer and animated it's x-size from 0 to 1920, but you are free to do whatever you like here.
In AE, there is no way to transport information from one frame to another. Therefore, the only solution to the "hold value" problem is to go through the whole timeline and recalculate, what happended there. This isn't very smart in general and if you have a very long timeline or massive calculations, you'll notice a performance gap when running such a code.
I added my project file for better understanding.
*Martin