Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Sorting returned numerical values of a ‘For Loop’

  • Sorting returned numerical values of a ‘For Loop’

    Posted by Dexter Decker on September 12, 2022 at 5:58 pm

    Hey,

    I have a control layer with a number of slider controls that I need sorted in numerical order, highest to lowest (all positive values). I’ve entered the following in the Source Text of a second layer and I get “TypeError: n.sort is not a function.”

     

    n = “”;

    for(i=1; i <5; i++){
    n += thisComp.layer(“Control”).effect(i)(1)
    n += “,”
    }
    n.sort(function(a,b){return a-b})

     

    If someone could help, I’d appreciate it.

     

    Thanks,

    Dex

    Dexter Decker replied 4 years ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    September 12, 2022 at 6:11 pm

    This seems to work, but I’m not sure if it’s what you’re after:

    n = [];
    for (i = 1; i < 5; i++){
    n.push(thisComp.layer("Control").effect(i)(1));
    }
    n.sort(function(a,b){return a-b})
  • Dexter Decker

    September 12, 2022 at 6:39 pm

    Sir, you are the GOAT! I thought it was something screwy with the data type, I tried to declare it as an array but that didn’t work either. Never knew a push function existed, must do some more reading. I’ve been playing with expressions for years now, haven’t really had time to study it. Recently I’ve made a greater effort to understand the language rather than hunting out expressions and patching pieces from here and there (some pretty gnarly looking projects that “worked”). I’m a big fan of your work and dedication to the community, you’re an absolute legend! Thanks so much for your time. You’re helping a lot of creatives like me (been lurking here for years).

    All the best,

    Dex

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