Highlighted

Running same code produces two different responses

New Here ,
Jul 03, 2020

Copy link to clipboard

Copied

I'm a complete beginner to AE expressions, but have programming experience in a few languages (not javascript). I was trying to write a script that set the content of a text object to a line in a .csv file that I imported. Basically I used Math.floor(time) to call a line from the csv file that changed every second. However, I was getting very strange output, and slowly simplified the expression until I got here:

 

var arr = ["a","b","c","d","e","f","g","h","i","j","k","l"];

arr[Math.floor(time)];

 

Note that this expression is going in the Source Text element of a text object I was working on. When I put the playhead at 0:00 and start the animation, the text changes every second, and displays the following letters in order before going blank: a b a d a f a h a j k l

 

For some reason, it's messing up on even numbered letters in the array, but stops once it gets to k. In my confusion, I made a brand new composition and a new text element, and immediately pasted this formula into the Source Text without making any other changes. When I set the playhead to 0:00 and ran it, I got: a b c d e f g h i j k l

 

This is exactly what I was expecting! I went back to the original function, confirmed the code was identical, and ran it. a b a d a f a h a j k l. Back to the new text object, and it's correct output.

 

At this point I have no idea what's going on whatsoever, so I play around with the code on the working text object some more and change the contents of the array. Nothing is working, so I go back to the original code. Suddenly, even this brand new text object is producing the incorrect output I was seeing before. I went a made a new text object and pasted the code, and this time it works again. For some reason, it appears that if I leave the object created for a little while and make some changes, it breaks its ability to execute this code.

 

Any idea what I'm doing wrong? This feels like an AE bug, but most problems tend to be user error so I won't discount that possibility.

TOPICS
Error or problem, Expressions, Scripting

Views

55

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Running same code produces two different responses

New Here ,
Jul 03, 2020

Copy link to clipboard

Copied

I'm a complete beginner to AE expressions, but have programming experience in a few languages (not javascript). I was trying to write a script that set the content of a text object to a line in a .csv file that I imported. Basically I used Math.floor(time) to call a line from the csv file that changed every second. However, I was getting very strange output, and slowly simplified the expression until I got here:

 

var arr = ["a","b","c","d","e","f","g","h","i","j","k","l"];

arr[Math.floor(time)];

 

Note that this expression is going in the Source Text element of a text object I was working on. When I put the playhead at 0:00 and start the animation, the text changes every second, and displays the following letters in order before going blank: a b a d a f a h a j k l

 

For some reason, it's messing up on even numbered letters in the array, but stops once it gets to k. In my confusion, I made a brand new composition and a new text element, and immediately pasted this formula into the Source Text without making any other changes. When I set the playhead to 0:00 and ran it, I got: a b c d e f g h i j k l

 

This is exactly what I was expecting! I went back to the original function, confirmed the code was identical, and ran it. a b a d a f a h a j k l. Back to the new text object, and it's correct output.

 

At this point I have no idea what's going on whatsoever, so I play around with the code on the working text object some more and change the contents of the array. Nothing is working, so I go back to the original code. Suddenly, even this brand new text object is producing the incorrect output I was seeing before. I went a made a new text object and pasted the code, and this time it works again. For some reason, it appears that if I leave the object created for a little while and make some changes, it breaks its ability to execute this code.

 

Any idea what I'm doing wrong? This feels like an AE bug, but most problems tend to be user error so I won't discount that possibility.

TOPICS
Error or problem, Expressions, Scripting

Views

56

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 03, 2020 0
Most Valuable Participant ,
Jul 05, 2020

Copy link to clipboard

Copied

Without any specific info on comp settings such as frame rate we can't really tell you much. There have been a few issues with NTSC-style timecodes, but otherwise this should work just fine. The array falling back to its first index could indicate such an issue when the returned time left over is zero. Have you tried to switch the expression engine back to the legacy version? Does the same happen there?

 

Mylenium

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 05, 2020 0
Guide ,
Jul 05, 2020

Copy link to clipboard

Copied

In addition to Mylenium, you should make a clean reboot of the computer and also purge the framecache. Issues like this are often resolved this way.

 

*Martin

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 05, 2020 0