Skip to main content
Javi Ge
Participating Frequently
April 13, 2021
Question

Expression issue

  • April 13, 2021
  • 2 replies
  • 1241 views

Hi to all,

 

I'm trying to save layers position's to an array and, later, recover them on depending of layer index and a random number pick up on a Null layer.

 

The expresion is this:

myArray=[];
for (var i = 1; i<=24;i++) {myArray.push(thisComp.layer(i).position.key(1));
}
 
res=chequeo();
 
function chequeo(){
var pos,x;
sliderNulo = thisComp.layer("Null 1").effect("01")("Slider");
miIndex = thisLayer.index;
 
if (sliderNulo+miIndex >= 24){
 
x=(sliderNulo+miIndex) - 24;
pos=x;
} else {
pos=sliderNulo+miIndex;
}
 
return pos;
}
 
 
myArray[res];
 
and the random number expression is this:
 
posterizeTime(3);
Math.abs(Math.floor(random(0,23)));
 
Thank you in advance
 
This topic has been closed for replies.

2 replies

Martin_Ritter
Legend
April 13, 2021

And what's the issue?

 

*Martin

Javi Ge
Javi GeAuthor
Participating Frequently
April 13, 2021

I'm getting this

 

when I want this

 

 

Martin_Ritter
Legend
April 13, 2021

I think those lines are creating the overlapping squares:

if (sliderNulo+miIndex >= 24){
   x=(sliderNulo+miIndex) - 24;
   pos=x;
 
If you exceed 24, you are starting at 0 again:
24 >= 24: 24-24; x = 0
25 >= 24: 25-24; x = 1
and so on
 
The code is a bit confusing... if you just want to collect all positions from all layers and randomly pick one postion for each layer, who not just:
   myArray=[];
   for (var i = 1; i<=24;i++) {
      myArray.push(thisComp.layer(i).position.key(1));
   }
 
   rndIndex = Math.floor(random(0,25));
   myArr[rndIndex];
 
I think you can even randomize the array (https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array) and take each layers index as array index to easily avoid douple postioning.
 
If you just aiming for shuffling colors, just randomize the color of each square.
 
Give us more details, so maybe we can point you to a better/working solution.
 
*Martin
Mylenium
Legend
April 13, 2021

And what exactly is your question (aside from the code generally making no sense)?

 

Mylenium

Javi Ge
Javi GeAuthor
Participating Frequently
April 13, 2021

Thank you Mylenium. The questiosn is that I wonder why is not working, I'm getting overlapping layers when I suppose to get distribuyed layers. The first 8 layers works poperly but the rest are repeating positions