-
What is wrong with my approach, and how does “my” solution actually works?
Hey all,
I needed to make a calendar in Ae, and I needed a loop of numbers going from 1 to 31. I thought I had enough knowledge of expressions to pull this off, but unfortunately I hadn’t.
This was my approach:
I made a new text layer and dropped a slider control on that.
in the source text of the layer, I create this expression:n = effect("Slider Control")("Slider");Math.round(n)
Now I simply made 2 keyframes om the slider from 1 to 31, and used the loopOut(“cycle”) expression to make it loop. I was now able to adjust the speed with the keyframes, and everything worked fine.
But I wanted to add one thing to it, and that took a lot more work than I thought. Basically I wanted to add a zero in front of the numer when the number was smaller than 10. So I thought I could make that with this expression:
n = effect("Slider Control")("Slider");Math.round(n)
if (n < 10){
n = "0" + n;
}else{
n = n;
}But this doesnt works. it doesnt add a 0 in front of the 1 digit numbers, but it also seems to mess up the Math.round expression.
After some googling I found some expressions to make this work:
s = effect("Slider Control")("Slider");
v = Math.round(time*s);
t = (v%31)+1;
padLength = 2;
t = t.toString();
while (t.length < padLength) {
t = "0" + t;
}
The only things I changed was the added slider for the speed (I believe the expression was v = Math.round(time/thiscompduration); of something like that.
It does exactly what I want, but I don’t understand exactly how. also, when I make v the slider value, it also gives me errors.
So my question is: What did do wrong in my approach, and how does the expression that works actually works? I’m really curious what toString actually does, what “(c%31)+1” does and why they used “while” instead of “if/else”
Regards,
Ramon Peppelenbos