-
Persistent state between frames
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?