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

Y-position based on index range

New Here ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

Hi,

I've been trying different variations of if - and index -expressions but to no avail.

I'm trying to get AE set the y-positions of layers between indexes 1-6 to 15, layers between 7-12 to 30 and so on.

The if-function works otherwise, but I can't figure out how to set a range for the indexes.

Thanks in advance for your help!

TOPICS
Expressions

Views

493

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 ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

Try this:

y = (Math.floor((index-1)/6)+1)*15;

[value[0],y]

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
New Here ,
Dec 29, 2017 Dec 29, 2017

Copy link to clipboard

Copied

Thanks Dan,

That works perfectly for what I was asking.

However, what if I wanted to set a position for certain range of indexes? Say 15 for 1-6, 30 for 7-24, 45 for 48-96 or something?

Is there a way to set a range in an IF -statement? I haven't been able to figure that out.

Something like

     if (thisLayer.index 1 to 6) (15)else(100);

Thanks

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 Beginner ,
Dec 29, 2017 Dec 29, 2017

Copy link to clipboard

Copied

LATEST

You could write a simple function to map the value as you would like. For instance:

function map(index){

  if(index<7){              return 15;}

  if(index<25){             return 30;}

  if(index>47 && index<97){ return 45;}

  else{                     return 0;}

}

map(index)

And of course you can use different functions, for instance the nicer/cleaner way Dan has proposed if that works in a particular case:

map(index, stepsize, amplitude){

  return (Math.floor((index-1)/stepsize)+1)*amplitude

map(index, 6, 15)

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