3 Replies Latest reply on Dec 29, 2017 6:12 AM by Vincent Bos

# Y-position based on index range

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.

• ###### 1. Re: Y-position based on index range

Try this:

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

[value[0],y]

Dan

• ###### 2. Re: Y-position based on index range

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

• ###### 3. Re: Y-position based on index range

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)
```