After Effects: Increment a Variable over time I have following problem:
I am trying to tweak the speed of a Math.sin function. Therefore I need a variable that incerements over time with a combination of a keyframed speed variable.

Sounds complicated, I know. 

Let's say I am using the global time variable and convert it with the timeToFrames() function I get an integer value for each frame.

myTime = timeToFrames(time);


This leads me to a value of 1 for Frame 1, a value of 2 for Frame 2, and so on.
But what if I want to manipulate the increment. For example:

//speed (gets tweened from a certain value range,for example: 10 - 1)
s = (some connected slider here)

myTime += s;


If I have a speed of 10 at Frame 1 I would get a value of 11. If I have a speed of 8 at Frame 2, I would expect a value of 11 + 2 + 8 = 21.

What I get is only 2 + 8;

So I need to store the value at every frame. Is this possible? 

Please help.
You can loop over the range of frames from the start of the comp to the present and calculate the value along the way.

function myFuncf(theTime){
 //whatever the function you're using to create the value, e.g.
 t=theTime + s.valueAtTime(theTime); //s is the slider
 return t
}

firstFrame = timeToFrames(inPoint); //if you want it to calculate
                                    //from the beginning of the comp
                                    //change this to 0, or maybe 1?
                                    //I'd check but I'm rendering ATM

mytime=0; //initialise the mytime variable

currentFrame = timeToFrames(time);
for (int i=firstFrame; i &lt;= currentFrame; i++){
  mytime += myFunc(framesToTime(i)); //need to convert frames back into seconds
}


after the loop myTime should be the sum of the results of function myFunc from all the previous frames up to and including the present one (I'm not 100% sure if the loop should end when i &lt; cf or i &lt;= cf, you might want to test).

note first time I posted this there was a mistake. Where I called the function I was giving it frames (from i the loop variable), but it uses valueAtTime which expects time in seconds, so you need to convert: mytime += myFunc(framesToTime(i));

If you have a long comp or this is applied to lots of layers, this expression may become slow to evaluate and cause lagginess. If it becomes a problem convert the expression to keyframes.