Skip to main content
SlimJimJam
Participant
August 14, 2022
Question

AE: String manipulation expression help

  • August 14, 2022
  • 1 reply
  • 227 views

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.

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
August 14, 2022

Maybe like this:

n = Math.floor(time/0.5)%4;
str = "";
for (i = 0; i < n; i++) str += ".";
str
SlimJimJam
Participant
August 14, 2022

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