FORUMS: list search recent posts

Random Numbers Reveal String

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
John Weingarten
Random Numbers Reveal String
on Jul 8, 2015 at 5:26:24 pm
Last Edited By John Weingarten on Jul 8, 2015 at 6:32:44 pm

Hello, I'm trying to create a text transition using expressions and having a bit of trouble.

I want Random numbers to scroll quickly, after 1 second I would like the first letter of the string to be "revealed" (ie replace the first digit). I can get the first letter to work, but it seems the variable i is only being increased once.

A bit new to expressions, so excuse me if this down to a simple syntax error. I've tried a number of combinations with nested if statements, else if statements...

If I output i instead of s, i = 1, until after 11 seconds, i = 2 and remains 2 even after 12, 13, 14 seconds.

timeToStart = effect("Start Time")("Slider"); // start at slider time (10)

string = "HELLO";
i = 1;

if (time > timeToStart){
s = "" + Math.floor(random(10000,99999));
if (time > timeToStart + i)
{
s = "" + Math.floor(random(1000,9999));
s = string.substr(0,i) + s;
i++;
}
}
else{
}
s


Return to posts index


Dan Ebberts
Re: Random Numbers Reveal String
on Jul 8, 2015 at 6:36:06 pm

Something like this should get you close:


timeToStart = effect("Start Time")("Slider"); // start at slider time

string = "HELLO";
s = "" + Math.floor(random(10000,99999));
if (time > timeToStart){
i = Math.floor(time-timeToStart);
s = string.substr(0,i) + s.substr(i);
}
s




Dan



Return to posts index

John Weingarten
Re: Random Numbers Reveal String
on Jul 8, 2015 at 8:07:15 pm

Thanks Dan, this is just what I needed. Should else if statements be avoided? From what I searched they should work in expressions.


Return to posts index


Dan Ebberts
Re: Random Numbers Reveal String
on Jul 8, 2015 at 8:51:24 pm

No reason to avoid if/else statements--they work fine in expressions. I think the issue with your expression might be that you were assuming that the value of i would survive from frame to frame, but there are no persistent variables in expressions.

Dan



Return to posts index

John Weingarten
Re: Random Numbers Reveal String
on Jul 9, 2015 at 1:53:25 pm

Makes sense, thanks.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]