Persistent state between frames
Copy link to clipboard
Copied
I have a layer with a car, and I have another Null layer with a speed controller that has manually placed keyframes.
I want to control the car position according to those speed keyframes, i.e. accumulate traveled distance. For example, if the spped values on the first 5 frames are 1, 2, 3, 4, 5 then positions should be 1, 3, 6, 10, 15.
I wrote this script and it works as intended:
sourceLayer = thisComp.layer("Null 1");
currentFrame = timeToFrames();
sum = 0;
for(i = 0; i <= currentFrame; i++) {
sum += sourceLayer.effect("speed")("Slider").valueAtTime(framesToTime(i));
}
sum
This becomes very inefficient as currentFrame increases. In reality I need some kind of persistent across frames storage, so I could just add one value to it every frame. Is that possible to do in Ae scripting system?
Copy link to clipboard
Copied
If your keyframes are linear and they don't happen every frame, you can probably gain some efficiancy by using a linear keyframe integrator, as discussed here:
https://www.motionscript.com/articles/speed-control.html#linear
but otherwise, theres no reliable way do persistent variables with expressions.
Copy link to clipboard
Copied
Is that possible to do in Ae scripting system?
Long and short: No.
Mylenium

