Activity › Forums › Adobe After Effects Expressions › while statement
-
while statement
Posted by Jamie Bradshaw on April 6, 2008 at 7:18 pmIs there an equivalent of a while/do statement in expressions?
I’m really struggling to find a way of achieving what I want with out it.
Thanks,
JamieJamie Bradshaw replied 18 years, 4 months ago 3 Members · 7 Replies -
7 Replies
-
Filip Vandueren
April 6, 2008 at 7:28 pmHere’s the basic syntax:
i=0;
while(i < 10){ i++; } or the do statement: i=0; do { i++; } while (i < 10); the difference between the two is: a "while" checks first if the condition is true, then executes and loops. a "do while" executes first, then checks if the condition is true to see if it should loop So there's a minimum of 1 run. -
Jamie Bradshaw
April 6, 2008 at 7:43 pmThanks Filip.
I might be back for further help with this as I’m still finding it a bit tricky to get what I’m after. 😉
Jamie
-
Jamie Bradshaw
April 6, 2008 at 8:15 pmHi again. I have pasted the (work-in-progress) expression I have in a layers position property below.
The problem I have is that I am looking to have a multi-dimensional array. The line that says:
tempPos[b] = add(posArray[b], mul(sub(posArray[b+1], posArray[b]), d));
I was hoping to be able to use this instead:
tempPos[a][b] = add(posArray[b], mul(sub(posArray[b+1], posArray[b]), d));
d = effect(“distribution”)(“Slider”);But it throws back a syntax error. Can anyone help? Sorry if this all seems a bit vague, I can try and clarify it a bit more if needed.
// Position expression
targetComp = comp(“controller”);
posArray = [0, 0, 0];
numPoints = 0;for (i=1; i <= targetComp.numLayers; i++) { L = targetComp.layer(i); if (L.name.substr(0,5) == "point") { numPoints++; posArray[numPoints] = L.position; } } a = (numPoints - 1); tempPos = [0, 0, 0]; while (a > 1) {
for (b=1; b<=a; b++) { tempPos[b] = add(posArray[b], mul(sub(posArray[b+1], posArray[b]), d)); } a--; } -
Dan Ebberts
April 6, 2008 at 8:29 pmWhat is it you’re trying to do, and why are you using all that old vector math stuff?
add(posArray[b], mul(sub(posArray[b+1], posArray[b]), d))
could be rewritten:
posArray[b] + (posArray[b+1] – posArray[b])*d
I don’t see where “d” is defined. If it varies over a known range (let’s say 0 to 1) you could use this instead:
linear(d,0,1,posArray[b],posArray[b+1])
Dan
-
Jamie Bradshaw
April 6, 2008 at 8:43 pmI’m afraid you’ll have to excuse my expressions Dan, I’m a bit of a novice and therefore it can be a bit untidy and unconventional. I was aiming to tidy it all up once I had it working.
What I am trying to achieve is to have a number of layers that are distributed along a bezier curve. The bezier curve is defined by the position of a number of layers (point000, point001 etc) in another composition.
I have this working, but I wanted the flexibility to be able to have any amount of point layers in my other composition.
d is defined at the start…
d = effect(“distribution”)(“Slider”); //normalised value of where this layer is distributed along the bezier curve
and in that Slider, I have this expression:
if (index == 1) {
i1 = 0;
} else {
i1 = ((index – 1) / (thisComp.numLayers – 1));
} -
Dan Ebberts
April 7, 2008 at 3:44 pmBack to your original question, if you declare your array like this:
tempPos = [[]];
then you can define individual elements like this:
tempPos[0][1] = [101,202,303];
and reference like this:
tempPos[0][1][2] // result = 303
Dan
-
Jamie Bradshaw
April 8, 2008 at 9:18 amThanks Dan. I actually refined the while loop in my expression and was able to get the result I was after just using a normal array. It works a treat now! 🙂
Thanks for your help though, that multi-dimensional array stuff is very useful to know.
Jamie Bradshaw
Motion Graphic Artist
https://www.vimeo.com/jimjam
Reply to this Discussion! Login or Sign Up