Skip to main content
Known Participant
March 27, 2022
Question

An expression error occurs only prior to a marker

  • March 27, 2022
  • 1 reply
  • 405 views

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];

 

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
March 28, 2022

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].

talwagAuthor
Known Participant
March 29, 2022

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!

Dan Ebberts
Community Expert
Community Expert
March 29, 2022

Or maybe something like this to keep from going off either end of the array:

m >= 0 && m < result.length ? result[m] : value;