Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Switch Case in text layer returns the switch the value, Having to use switch(true)

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

    Posted by Frederic Antoinette on August 28, 2018 at 7:33 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?

    Frederic Antoinette replied 7 years, 8 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andreas Brand

    August 28, 2018 at 8:44 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;
    }

  • Frederic Antoinette

    August 29, 2018 at 6:37 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy