Copy link to clipboard
Copied
Hi,
I feel like the answer to this is probably a resounding "no" but figured i'd ask out there for those who know buckets more than i do.
If i have a line of text typing on (say, with the typewriter effect) is there a way to recognize at any given time what the last character typed was?
(With the idea that then you could link an object property to a character—e.g. when an A is typed on, an object scale animation is activated.)
Thanks for any thoughts anyone has on this!
-tim.
Copy link to clipboard
Copied
First-- this feels like more of an Expressions question, not a scripting question.
This could be doable depending entirely on the method you use to have the text type on, and the start/end range selector values, and most of the values in the 'Advanced' dropdown of the range selector.
With just Typewriter, set to the defaults, which are:
You can use an expression like this to give you the most recent revealed character:
// Get the reference text content
var referenceText = thisComp.layer("Hi timhubner!").text.sourceText;
// Get the value of the animated Start selector
var selectorPct = thisComp.layer("Hi timhubner!").text.animator("Animator 1").selector("Range Selector 1").start;
// Get the index of the last shown character, based on the selector percentage and length of source text
var lastShownCharIndex = Math.round(selectorPct / 100 * referenceText.length);
// Get only the character from the index above
var lastCharacter = referenceText.charAt(lastShownCharIndex - 1);
Once you have it, then you can start exploring what you want it to do. Tiggering and playing back animation is a rabbit hole of loops and ifs and checks, so it may not be the best approach for what you're after, but this should be a good start to at least get that last character!
A gif of what this would look like is below. At the top is the 'Typewriter' effect on a text layer, and at the bottom I'm showing only the last character using the expression above.
Copy link to clipboard
Copied
Moved from After Effects Scripting to After Effects Expressions
Copy link to clipboard
Copied
Sorry for the slow reply, but thanks for the help!
That definitely gets me started down the right path.