Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Copy-paste goes wrong

  • Copy-paste goes wrong

    Posted by Clement Dubois on February 26, 2022 at 9:22 pm

    Hi 👋

    So I have an expression that work just fine, I have to duplicate it on several others layers, but when I do it, many expression don’t work anymore.

    It is strange because the same expression could work on the layer just below the one that is not…

    When I move the playhead, some expressions still don’t work and others get fixed by… magic ? 🤔

    I really don’t understand, I tried to type the code by hand but nothing changed.

    To be more specific, this is the same code, going on shape layers, on fill property.

    On every not working expression the same issue is being showed, “Undefined value used in the expression…”

    Here’s the code :

    f = thisComp.layer("BG").content("Fill 1").color;
    colors = [[1, 1, 1, 1],
    [0, 1, 1, 1],
    [0, 0, 1, 1],
    ];
    yellow = [colors[0],
    colors[1],
    colors[2],
    ];
    purple = [colors[1],
    colors[0],
    colors[2],
    ];
    pink = [colors[2],
    colors[0],
    colors[1],
    ];

    seedRandom(index,true);

    idx = Math.floor(random(colors.length));
    if (f.numKeys > 0){
    n = f.nearestKey(time).index;
    if (time < f.key(n).time) n--;
    for (i = 1; i <= n; i++){
    idx = (idx + Math.floor(gaussRandom(0,2)))%colors.length;
    }
    }
    if (length(f, colors[0])<0.001){
    yellow[idx]
    }else if (length(f, colors[1])<0.001){
    purple[idx]
    }else{
    pink[idx]
    }
    Dan Ebberts replied 4 years, 2 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    February 26, 2022 at 10:18 pm

    Math.floor(gaussRandom(0,2)) is going to give you the occasional -1, and if that happens when idx is 0, you’ll get an illegal array index.

  • Clement Dubois

    March 1, 2022 at 5:37 am

    Could I use clamp() ? I tried but it not worked.

    🤔

  • Dan Ebberts

    March 1, 2022 at 6:56 am

    clamp(Math.floor(gaussRandom(0,2)),0,1) should work.

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