Mailing List AE-List@media-motion.tv — Message #64189
From: Robert Kjettrup <AE-List@media-motion.tv>
Subject: Re: [AE] Try Catch expression
Date: Fri, 6 Jul 2018 17:52:37 +0200
To: After Effects Mail List <AE-List@media-motion.tv>
Hi Steve

ofcourse i should do that instead, sometimes the answer is so obvious that you dont see it :-D... im already using sourceText.length for turning on/off layers so i dont know why i didn't think of this.
Thank you Steve. much appreciated for getting me in the right direction


The error was just a generic invalid numeric value:
"invalid numeric result (divide by zero?)."

it makes sense since it tries to return a value from a string character that doesnt exists.

down to 0 errors now :-)



2018-07-06 17:09 GMT+02:00 Steve Zuranski <AE-List@media-motion.tv>:
I have not tested this and I have not done any AE scripting in years. Why don't you inspect the length of the string before you attempt to read at an out of bounds index rather than using a try catch statement?

Also what do the error messages say? That will help in determining the cause.

// Get the length of the string.
txtVal = thisComp.layer("ab").text.sourceText;
fps = 1/thisComp.frameDuration;
Ch = 3;
length = txtVal.value.text.length;

if(length >= Ch-1) {
txtVal.charCodeAt(Ch-1)/fps;
}else{
0;
}


On Fri, Jul 6, 2018 at 10:04 AM Steve Zuranski <szuranski@gmail.com> wrote:
I have not tested this and I have not done any AE scripting in years. Why don't you inspect the length of the string before you attempt to read at an out of bounds index rather than using a try catch statement?

Also what do the error messages say? That will help in determining the cause.

// Get the length of the string.
txtVal = thisComp.layer("ab").text.sourceText;
fps = 1/thisComp.frameDuration;
Ch = 3;
length = txtVal.value.text.length;

if(length >= Ch-1) {
txtVal.charCodeAt(Ch-1)/fps;
}else{
0;
}


On Fri, Jul 6, 2018 at 6:07 AM Robert Kjettrup <AE-List@media-motion.tv> wrote:
Hi

im using .charCodeAt() to get a Unicode value from a textlayer to timeremap a precomp, this is working great to use custom graphics to type out words.

But im having a small problem with AE giving me an expression error if i use the charCodeAt() to read from a chararcter there is higher than the length of the textstrring of the text layer


This error is not really problematic since it renders fine.... but now that i have set up a larger project i have the expression warning banner tell me about 55 errors, and that is quite annoying.

Now im trying to use the Try Catch to get AE to ignore this error and not return a warning for each layer that has this expression reading outside the length of a textstring... but i cant get it to work.
What am i doing wrong.

the setup is as follows:

a precomp with a bitmat characters setup at framenumbers that match the Unicode value that .charCodeAt() returns.

This expression on the TimeRemap property of each copy of the character comp, this is character 3, aka copy 3 of this comp:


txtVal = thisComp.layer("ab").text.sourceText;
fps = 1/thisComp.frameDuration;
Ch = 3;
txtVal.charCodeAt(Ch-1)/fps


And the Try/Catch method i cant get to work 

txtVal = thisComp.layer("ab").text.sourceText;
fps = 1/thisComp.frameDuration;
Ch = 3;
try { txtVal.charCodeAt(Ch-1)/fps } catch(err) { 0 }



and a link to a screengrab of a simplified version of my setup:
https://adobe.ly/2NtbdHv

 
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to ListMaster