Skip to main content
mart-martinlofqvist
Known Participant
October 12, 2023
Question

Looping through a specific bit of text gives me unstable result

  • October 12, 2023
  • 1 reply
  • 131 views

Hi! 

 

Working with text wanting to be able to specify which exact part of the whole text I want to fetch. The setup now is Point Expression Control that defines the start and the end of the splitted string and render it using a for loop. It works, but. The result is unstable when I'm changing the start value, often it gets stuck at "UNDEFINIED". 

 

t = thisComp.layer("txtSource").text.sourceText; 
t = t.split(" ");
txtFrom = effect("txt FromTo ")("Point")[0]; 
txtTo = effect("txt FromTo ")("Point")[1]; 
t2 = "";
for (i = txtFrom; i < txtTo; i++) {
	t2 += t[i] + " ";
}

l1 = thisComp.layer("Font STYLE 1").text.sourceText;
l2 = thisComp.layer("Font STYLE 2").text.sourceText;
l3 = thisComp.layer("Font STYLE 3").text.sourceText;


textStyles = [l1, l2, l3];
c = clamp(effect("current style")("Slider"), 0, textStyles.length-1);


style = textStyles[c].getStyleAt(0,0);
style.setText(t2);

that's the entire code, that also fetches styles from three different layers. 

 

I'm guessing there is some kind of try or break function that I need to add? Anyone has an idea how to make this more stable?  

This topic has been closed for replies.

1 reply

mart-martinlofqvist
Known Participant
October 12, 2023

Oh snap. As I posted I just realised I just need to take care of the decimals of the start and stop variables. 

Using Math.floor() on the txtFrom and txtTo values this now seems to work. 

 

Leaving the thread as if anyone else might be helped by this easy solution.