Skip to main content
Known Participant
March 22, 2022
Answered

else if statement with multiple conditions - I'm confused

  • March 22, 2022
  • 1 reply
  • 1667 views

Im struggling with an else if statement.

I have 17 text layers.
3 drop menus (drA, drB, drC) with 15 objects in each.
and 3 markers (A, B, C) on a layer.

I want every text layer the be bold only when the right condition is met.
for example,
if drA == 1
and the time is between markers A and B,
layer 1 will be bold.
and when time goes beyond marker B, layer 1 will become regular again, unless drB is set to 1 too.
same goes for the rest of the text layers.


i wrote down this expression and I think the conditions are not mutually exclusive, because when time goes beyond the first marker, the layer becomes bold and stays.
anyway is doesn't work.

this is the expression:

 

dr1 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky A")("Menu").value;
dr2 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky B")("Menu").value;
dr3 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky C")("Menu").value;

b = text.sourceText.style.setFont("Avenir-Black");
r = text.sourceText.style.setFont("Avenir-Medium");


catM = comp("ASA_LL_sky_UI").layer("Sky CAT controller").marker;
menus =  comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect(1)("Menu").value;


cA = time > catM.key(1).time && time < catM.key(2).time;
cB = time > catM.key(2).time && time < catM.key(3).time;
cC = time > catM.key(3).time;


if 		(dr1 == index-6 && cA) b;
else if (dr1 == index-6 && cB) b;
else if (dr1 == index-6 && cC) b;

else if (dr2 == index-6 && cA) b;
else if (dr2 == index-6 && cB) b;
else if (dr2 == index-6 && cC) b;

else if (dr3 == index-6 && cA) b;
else if (dr3 == index-6 && cB) b;
else if (dr3 == index-6 && cC)
{b} else {r};
This topic has been closed for replies.
Correct answer Dan Ebberts

I'd do it like this (I think):

dr1 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky A")("Menu").value;
dr2 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky B")("Menu").value;
dr3 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky C")("Menu").value;

b = "Avenir-Black";
r = "Avenir-Medium";

catM = comp("ASA_LL_sky_UI").layer("Sky CAT controller").marker;

if (time < catM.key(1).time){
  f = r;
}else if (time < catM.key(2).time){
  f = dr1 == index-6 ? b : r;
}else if (time < catM.key(3).time){
  f = dr2 == index-6 ? b : r;
}else{
  f = dr3 == index-6 ? b : r;
}
text.sourceText.style.setFont(f)

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
March 22, 2022

I'd do it like this (I think):

dr1 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky A")("Menu").value;
dr2 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky B")("Menu").value;
dr3 = comp("ASA_LL_sky_UI").layer("Sky CAT controller").effect("Sky C")("Menu").value;

b = "Avenir-Black";
r = "Avenir-Medium";

catM = comp("ASA_LL_sky_UI").layer("Sky CAT controller").marker;

if (time < catM.key(1).time){
  f = r;
}else if (time < catM.key(2).time){
  f = dr1 == index-6 ? b : r;
}else if (time < catM.key(3).time){
  f = dr2 == index-6 ? b : r;
}else{
  f = dr3 == index-6 ? b : r;
}
text.sourceText.style.setFont(f)
talwagAuthor
Known Participant
March 23, 2022

Thats awesome! and so much simpler then what I tried to do...

I learn a lot from it. Thanks you!