Skip to main content
This topic has been closed for replies.

1 reply

Participant
March 17, 2023

Hi please help, I'm getting this error again and again.

This is the expression

startYear = 1900;
currentYear = 2023;
if (typeof time === "number") {
currentYear = Math.floor(time/31536000) + startYear;
}
months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
currentMonth = "";
if (typeof time === "number") {
currentMonth = months[Math.floor(time/2592000) % 12];
}

x = transform.position[0];
y = 0;
if (typeof time === "number") {
y = transform.position[1] - (currentYear - startYear) * 30;
}
[value[0], y]

if (typeof time === "number") {
currentYear + " " + currentMonth;
} else {
"";
}

How to fix it.

This expression calculates the current year based on the start year and the number of seconds that have passed since the composition started. It also calculates the current month based on the same time value. The expression then sets the Y position of the text layer based on the current year and the start year, and adds the current year and month as text next to the year.

To use this expression, create a text layer and apply the expression to its Position property. You can then keyframe the X position of the layer to make the text slide up and the next year appear.


I don't know why it's not working

 

Dan Ebberts
Community Expert
Community Expert
March 17, 2023

The maximum value that time can have is 10800 (which would happen at the end of a 3-hour comp) so your currentYear will always be 1900. But the actual reason for the generated error is the last 5 lines, where you're generating text instead of a numeric result for position.