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!
Copy link to clipboard
Copied
Try this:
y = (Math.floor((index-1)/6)+1)*15;
[value[0],y]
Dan
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
Copy link to clipboard
Copied
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)