Skip to main content
Participant
July 2, 2023
Answered

Adobe After Effects Expression

  • July 2, 2023
  • 2 replies
  • 680 views

var x = 0;

 

var y = 2;

 

var z = 10;

 

I want var x value to be increased by 1 (x + 1) after every var y seconds untill time is equal to var z.

 

What to do?

This topic has been closed for replies.
Correct answer Mathias Moehl

Dan's idea to use floor to increase by 1 is very elegant. But I think your condition with the z must be implemented like this (since z should be a limit on the time, not on the final value, if I understand it correctly):

x = Math.floor(Math.min(time,z)/y);

2 replies

Mathias Moehl
Community Expert
Mathias MoehlCommunity ExpertCorrect answer
Community Expert
July 2, 2023

Dan's idea to use floor to increase by 1 is very elegant. But I think your condition with the z must be implemented like this (since z should be a limit on the time, not on the final value, if I understand it correctly):

x = Math.floor(Math.min(time,z)/y);

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Dan Ebberts
Community Expert
Community Expert
July 2, 2023

Expressions don't have memory, so variables don't survive from one frame to the next, but you can calulate your x value based on the current time, like this:

var x = 0;
var y = 2;
var z = 10;

x += Math.floor(time/y);
x = Math.min(x,z);

or elapsed time since the layer's in point, like this:

var x = 0;
var y = 2;
var z = 10;

x += Math.floor((time-inPoint)/y);
x = Math.min(x,z);