-
Reverse text lines in a text array
Hello Creative Cow hivemind,
My project is kind of complicated and I’m not a native speaker but I will try my best to make my explanation and project as understandable (and short) as I can.
I’ve linked a text layer (t1) in Comp A to display the text line from a text layer (t2) in Comp B that is hooked up to a slider (s). t1 changes to the appropriate line in t2 depending on the slider value. Every line in t2 is divided by a line break.
s = Math.floor(comp("Comp B").layer("Slider").effect("Slider"));
Text = comp("Comp B").layer("t2").text.sourceText;if (s == 0) {
Text.split("\r")[20];
}else if (s == 1) {
Text.split("\r")[18];
}[...] (you get the idea)
else if (s == 10) {
Text.split("\r")[0];
}<div>This works fine with 20 text lines (10 lines + 10 line breaks), but since the anchor point of t2 is at the left bottom to write text from the left and from the bottom up, t1 returns empty when there are less lines because it counts the lines reversed to what I need it to do. Basically what I need it to do is work like
</div><div>if (s == 0) {
Text.split("\r")[0];
}</div><div>
but actually use [20] if there are 10 text lines and 10 line breaks and be dynamic to how many lines (up to 10) there are.
I found out that there is a .reverse() which should “reverse elements and return the new array” but A) I’m not 100% sure if that is what I want and B) I can’t get it to work to see if that’s what I want ?
Any ideas?
Thanks!
Edit: Sorry for the (div)’s, no idea where they are coming from and I can’t get rid of them because they disappear in edit mode.
</div>
Sorry, there were no replies found.