-
How to set global variables and/or Functions in composition
I have a massive piece of code that sets variables by referencing sliders in a control layer.
I have 30 layers where I apply this same piece of code. If I need to adjust the code, I have to delete 29 layers, and then re-do them all haha. It’s crazy.
Is there some way to make my variables global, so those variables apply to all layers? Can I get a function to apply to all layers?
myID = effect("myID")("Slider");firstPhotoInPoint = thisComp.layer("Control Sliders").effect("firstPhotoInPoint")("Slider");
checkSections = thisComp.layer("^sections").text.sourceText;
sectionOneStart = thisComp.layer("Control Sliders").effect("sectionOneStart")("Slider");
sectionOnePhtNum = thisComp.layer("Control Sliders").effect("sectionOnePhtNum")("Slider");
sectionOneDur = thisComp.layer("Control Sliders").effect("sectionOneDur")("Slider");
sectionOnePhtTime = sectionOneDur / sectionOnePhtNum;sectionTwoStart = thisComp.layer("Control Sliders").effect("sectionTwoStart")("Slider");
sectionTwoPhtNum = thisComp.layer("Control Sliders").effect("sectionTwoPhtNum")("Slider");
myIDSectionTwo = myID - sectionOnePhtNum;
sectionTwoDur = thisComp.layer("Control Sliders").effect("sectionTwoDur")("Slider");
sectionTwoPhtTime = sectionTwoDur / sectionTwoPhtNum;sectionThreeStart = thisComp.layer("Control Sliders").effect("sectionThreeStart")("Slider");
sectionThreePhtNum = thisComp.layer("Control Sliders").effect("sectionThreePhtNum")("Slider");
myIDSectionThree = myID - sectionOnePhtNum - sectionTwoPhtNum;
sectionThreeDur = thisComp.layer("Control Sliders").effect("sectionThreeDur")("Slider");
sectionThreePhtTime = sectionThreeDur / sectionThreePhtNum;sectionFourStart = thisComp.layer("Control Sliders").effect("sectionFourStart")("Slider");
sectionFourPhtNum = thisComp.layer("Control Sliders").effect("sectionFourPhtNum")("Slider");
myIDSectionFour = myID - sectionOnePhtNum - sectionTwoPhtNum - sectionThreePhtNum;
sectionFourDur = thisComp.layer("Control Sliders").effect("sectionFourDur")("Slider");
sectionFourPhtTime = sectionFourDur / sectionFourPhtNum;sectionFiveStart = thisComp.layer("Control Sliders").effect("sectionFiveStart")("Slider");
sectionFivePhtNum = thisComp.layer("Control Sliders").effect("sectionFivePhtNum")("Slider");
myIDSectionFive = myID - sectionOnePhtNum - sectionTwoPhtNum - sectionThreePhtNum - sectionFourPhtNum;
sectionFiveDur = thisComp.layer("Control Sliders").effect("sectionFiveDur")("Slider");
sectionFivePhtTime = sectionFiveDur / sectionFivePhtNum;if (checkSections == "sections" && myID <= sectionOnePhtNum) {
timeElapsed = sectionOnePhtTime * (effect("myID")("Slider") - 1);
timeStart = firstPhotoInPoint + timeElapsed;} else if (checkSections == "sections" && myID <= (sectionOnePhtNum + sectionTwoPhtNum)) {
timeElapsed = firstPhotoInPoint + sectionOneDur + (sectionTwoPhtTime * (myIDSectionTwo - 1));
timeStart = timeElapsed;} else if (checkSections == "sections" && myID <= (sectionOnePhtNum + sectionTwoPhtNum + sectionThreePhtNum)) {
timeElapsed = sectionThreeStart + (sectionThreePhtTime * (myIDSectionThree - 1));
timeStart = timeElapsed;} else if (checkSections == "sections" && myID <= (sectionOnePhtNum + sectionTwoPhtNum + sectionThreePhtNum + sectionFourPhtNum)) {
timeElapsed = sectionFourStart + (sectionFourPhtTime * (myIDSectionFour - 1));
timeStart = timeElapsed;} else if (checkSections == "sections" && myID <= (sectionOnePhtNum + sectionTwoPhtNum + sectionThreePhtNum + sectionFourPhtNum + sectionFivePhtNum)) {
timeElapsed = sectionFiveStart + (sectionFivePhtTime * (myIDSectionFive - 1));
timeStart = timeElapsed;} else {
photoTime = thisComp.layer("Control Sliders").effect("photoTime")("Slider");
timeElapsed = photoTime * (effect("myID")("Slider") - 1);
timeStart = firstPhotoInPoint + timeElapsed;}
valueAtTime(time - timeStart);
Evan Jenkins
Aspen Films Inc.
aspenfilms.ca