• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Confused with array syntax

Engaged ,
Oct 08, 2009 Oct 08, 2009

Copy link to clipboard

Copied

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?

TOPICS
Expressions

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Oct 08, 2009 Oct 08, 2009

Copy link to clipboard

Copied

> 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 09, 2009 Oct 09, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2009 Oct 09, 2009

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines