-
Weird expression behavior, please help.
Hello, y’all!
So I’m dabbing into expressions, and I’ve played with JS before, but I’m no expert and I don’t know how to identify this weirdness and can use some fresh new eyes.
So I have this expression in a shape layer for the Size, Rotation and Stroke, and a Null with expression control sliders.
I designed the expression that if I duplicate the shape layer, it will read:
1. Read the layer name and store it in a value2. See’s the layer below it and increase the scale and rotation so I get this cool shape pattern effect.
3. The scale/rotation values and offsets are controlled by the null.
Everything (sorta) works as intended (check the GIF), but when it gets to layer 10, it kinda just resets to the scale and rotation values to the first layer. I can’t seem to figure it out. What did I do wrong? To replicate it, simply delete all the Octagon shape layers, but leave Octagon 1. Now duplicate it, and you’ll the new shapes created, but the 10th shape will just reset to the initial value.
I’ve attached the AE file and you’ll see that the scale and rotation value of “Octagon 10” is the same as “Octagon 1” and just repeats at that point instead of just building off the shapes.
I’ll copy the script of the shape layer’s scale property. Thank you in advance!
//get layer name
layerVal = thisLayer.name;//get the number from the layer
layerVal = layerVal.replace(/[^1-9]/g, '')//get just the text
layerTxtVal = layerVal.replace(/[^a-z]/g, '')//convert the string number into an integer
layerNumVal = parseInt(layerVal);xScale = 10; //just place holders
yScale = 10; //just place holders//check if layer is labeled as "1", if so, don't try looking for layer 0(zero)
if(layerNumVal > 1){
//Layer is grater than 1, do something
//get the layer one level down
layerNumVal = layerNumVal - 1;
xScale = thisComp.layer("Octagon "+layerNumVal).transform.scale[0]+thisComp.layer("Octagon Null").effect("Scale Offset")("Slider")
yScale = xScale;
} else {
//Layer is #1 Look at null value controls
xScale = thisComp.layer("Octagon Null").effect("Scale")("Slider")
yScale = xScale;
}
[xScale,yScale]