Skip to main content
tunghoy
Inspiring
October 9, 2009
Question

Confused with array syntax

  • October 9, 2009
  • 1 reply
  • 1642 views

If I want to wiggle the X, Y and Z dimensions of a layer's position, I can do it with this expression:

[wiggle(3,4)[0],wiggle(4,5)[1],wiggle(5,6)[2]]

This addresses each dimension as an array member by index number.

But if I want to randomize the  dimensions, I have to use syntax like this:

[random(0,100),random(10,50),random(50,80)]

If I try to explicitly reference the array members when using the Random function, AE throws an error.

So how do I know which functions require addressing array members by index number and which functions require that I don't?

This topic has been closed for replies.

1 reply

Todd_Kopriva
Inspiring
October 9, 2009

> So how do I know which functions require addressing array members by index number and which functions require that I don't?

Look at the expression reference page for the random method.

If you pass an array or pair of arrays to random, you get an array back. If you pass a number or pair of numbers, you get a number back.

In your example, you're passing a pair of numbers to each call to random, so you're getting a number back.

tunghoy
tunghoyAuthor
Inspiring
October 9, 2009

Thanks for your reply. From the page you referred to, I see I can simplify my Random expression for X, Y and Z as:

random([0,100],[4,5],[5,6])

That's good. I understand that if I randomize only 1 value, it's a number, not an array. But what's confusing me is that whether I write a Random expression the long way or the short way to randomize X and Y or X, Y and Z values, I have to pass an array, because the Position property itself is an array -- and I have to pass the array implicitly. If I pass the array explicitly, as I have to with Wiggle, AE throws an error.

My confusion isn't with the Random function itself. I'm wondering if there is a rule that tells me when to pass an array implicitly or explicitly. Or do I have to look at the syntax of each function to find out? With JavaScript, I have a choice of 3 ways to create an array, but AE seems to be more particular.

Dan Ebberts
Community Expert
Community Expert
October 9, 2009

Actually, your random expression would look like this:

random([0,10,50],[100,50,80])

giving you an x range of 0 to 100, y of 10 to 50, and z of 50 to 80.

wiggle() generates values of the same dimension as the property to which it is applied.

random() takes one or two  parameters (scalars or arrays). If you only provide one parameter, the other is assumed to be zero, (or [0,0], or [0,0,0], or [0,0,0,0], etc.) and generates values with dimensions matching the parameters that you supply.

Dan