AE: String manipulation expression help

New Here ,
Aug 14, 2022 Aug 14, 2022

Copy link to clipboard

Copied

Hi guys,

New to ExtendScript/JavaScript and trying to "git gud" at expressions with a simple string manipulation expression.

The goal is for it to add a dot ( . ) every half second until there's 3, reset back to 0 and loop, without using keyframes.

Everything I've written has either returned errors or crashed AE. This is the closest I've gotten:

Expression on "Source Text" animator, Source Text is "Testing".

 

var dots = "";
var sw = thisComp.layer("Dot Switch").effect("Checkbox Control")("Checkbox");
var output = ""
var count = 0
var dur = thisComp.frameDuration
var t = 0

 

while( sw == 1 && t < time){
if(Number.isInteger(Math.floor(time*4)/2) == true){
dots += "."
count += 1
}
output = text.sourceText + dots
}
output

 

At one point it kept adding dots (as intended until I put in a limiter using 'count', but now it just crashes AE every time I run it. Any advice on what I'm doing wrong would be appreciated.

 

Thanks!

James.

TOPICS
Expressions , Freeze or hang

Views

51

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
community guidelines
Community Expert ,
Aug 14, 2022 Aug 14, 2022

Copy link to clipboard

Copied

Maybe like this:

n = Math.floor(time/0.5)%4;
str = "";
for (i = 0; i < n; i++) str += ".";
str

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
community guidelines
New Here ,
Aug 14, 2022 Aug 14, 2022

Copy link to clipboard

Copied

LATEST

Thanks for your reply Dan,

 

That's alot more elegant than the solution I've reached by crashing AE about 100 times; I added two controls to enable/disable and vary the rate of delay, it works well but stille crashes AE if you set the slider to 0; which I'm sure could be easily caught if anyone wants to improve on it. The toFixed(2)'s were just for readability whilst debugging, I don't think they're necessary.

 

Cheers

var dots = "";
var sw = thisComp.layer("Dot Controls").effect("Enabler")("Checkbox");
var output = ""
var d = 0

while( sw == 1 && d <= time.toFixed(2)){
		dots += "."
		d += (thisComp.layer("Dot Controls").effect("Frame Delay")("Slider") * thisComp.frameDuration.toFixed(2))
	if(dots != "" && dots != "." && dots != ".." && dots != "..."){
	dots = ""
	}
}

output = text.sourceText + dots

 

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
community guidelines