ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Switch Case in text layer returns the switch the value, Having to use switch(true)

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Frederic Antoinette
Switch Case in text layer returns the switch the value, Having to use switch(true)
on Aug 28, 2018 at 7:33:19 am
Last Edited By Frederic Antoinette on Aug 28, 2018 at 7:35:16 am

Created a pseudo effect for a template, with a popup.
And depending on the what is on the popup the sentence should change.
here is the code
sel = thisComp.layer("Control").effect("Carry Forward")("First Message");
switch(sel){
case 1:
"CARRY FORWARD PICK 6" ;
break;

case 2:
"CARRY FORWARD PICK 8";
break;

case 3:
"CARRY FORWARD PICK 4";
break;
}


However though it doesn't give me any error it ends up with the text displaying the "sel" value.
That is "1", "2", or "3" instead of the sentence.

I also tried to put
value = "...." in the cases
same results

Searching the web I saw something about a switch using "true" instead of a variable, this one worked:

sel = thisComp.layer("Control").effect("Carry Forward")("First Message");
switch(true){
case (sel ==1):
"CARRY FORWARD PICK 6" ;
break;

case (sel == 2):
"CARRY FORWARD PICK 8";
break;

case (sel == 3):
"CARRY FORWARD PICK 4";
break;
}


Any idea why the first one didn't work, shouldn't it have the same results?


Return to posts index

Andreas Brand
Re: Switch Case in text layer returns the switch the value, Having to use switch(true)
on Aug 28, 2018 at 8:44:43 am

I tried it with a slider control and it didn't worked out until I rounded the number.

Maybe this will help your problem too.

sel = Math.floor(thisComp.layer("Control").effect("Carry Forward")("First Message"));
switch(sel){
case 1:
"CARRY FORWARD PICK 6" ;
break;

case 2:
"CARRY FORWARD PICK 8";
break;

case 3:
"CARRY FORWARD PICK 4";
break;
}


Return to posts index

Frederic Antoinette
Re: Switch Case in text layer returns the switch the value, Having to use switch(true)
on Aug 29, 2018 at 6:37:34 am

Good catch.
It worked
I would have done that if I was using a slider, but I though with a pseudo popup it wouldn't be needed.
So I guess I will call it a little bug that the value of these pseudo popup effects are not exact integers and we need to round it.

Thanks


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]