Copy link to clipboard
Copied
I have a shape layer (let's call it "Shape layer") that its position "In" animation is triggered by a marker that is on another layer in an other composition (let's call it "Controller layer").
everything works fine, but I have an error appears on the position expression on "Shape layer" only when the time indicator is located before the first marker on the "Controller layer".. whenever the time is ahead of the marker, the error disappears.
There are three shape layers and the issue occurs on all three of them.
This is the error:
Error: Undefined value in expression (could be an out of range array subscript?)
This is the expression written on the position of the "Shape layer":
m = comp("ASA_LL_sky_UI").layer("Click controller A").marker.key(2).comment;
const cm = comp("ASA_LL_sky_UI").layer("Click controller A").marker;
const catM = comp("ASA_LL_sky_UI").layer("Sky CAT controller").marker;
let latestMarkerIndex = 0;
if (catM.numKeys > 0) {
latestMarkerIndex = cm.nearestKey(time).index;
if (cm.key(latestMarkerIndex).time > time) {
latestMarkerIndex--;
}
}
let outputText = "";
if (latestMarkerIndex > 0) {
const latestMarker = cm.key(latestMarkerIndex);
outputText = latestMarker.comment;
};
menus = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect(1)("Menu").value;
yVals = [371,634,896,1157,1416,1684,1950,2208,2470,2730,2995,3254,3515,3781,4038];
m = outputText-1;
y = yVals[menus-1];
result = [
[ 159.0632 , y ],
[ 349.0632 , y ],
[ 540.0632 , y ],
[ 731.0632 , y ],
[ 920.0632 , y ]
];
result[m];
Copy link to clipboard
Copied
Before the first marker, latestMarkerIndex will be 0, which means outputText will be "", which means m will be ""-1, which won't provide a valid array index when the expression tries result[m].
Copy link to clipboard
Copied
I see. so I tought of trying to add another value at the top of the array and somehow call this value, but no success here.
Then, I wrote this line:
outputText > 0 ? result[m] : value;
at the end, insead of result[m].
and I was very pleased to see that it works!
Copy link to clipboard
Copied
Or maybe something like this to keep from going off either end of the array:
m >= 0 && m < result.length ? result[m] : value;
Copy link to clipboard
Copied
What is the reason for using .length here?
Which data it referts to?
Copy link to clipboard
Copied
.length gives you the number of elements in your result array, so result.length-1 is the last valid index into the array. It depends on what you want to happen if you have a marker with a number that is too large for the number of elements in your array.