Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Numerical order

  • Numerical order

  • Scott McGee

    September 18, 2017 at 1:18 pm

    I have 5 Text Layers. More in the future, just trial testing at the moment. Essentially, we want to build a football league table.

    We type in the wins, loses and draws. This give us our final number below.

    10
    5
    11
    8
    15

    Each text layer has a position above and below one another….

    Is there an expression that can work out the numerical order. So the positions will change

    5
    8
    10
    11
    15

    I can think of a few ways, but I want to maybe look at 20 layers and it’s getting a little messy.

  • Scott McGee

    September 18, 2017 at 7:50 pm

    I’m not great when it comes to Arrays, I’ve tried giving below a try, but it’s not working in the slightest for me.

    scores = [300,800,200,500,0,500];

    scoresIndices = new Array(scores.length);
    for (i = 0; i < scores.length; i++) scoresIndices[i] = [scores[i],i];

    scoresIndices.sort(function(a,b) {return b[0] – a[0]});

    scoresIndices[0][1]

    https://forums.creativecow.net/docs/forums/post.php?forumid=2&postid=1040199&univpostid=1040199&pview=t

  • Scott McGee

    September 19, 2017 at 7:32 am

    Figured out what the issue is, but could anyone suggest how to fix this?

    array = [12,5,9,10,3]
    array.sort()[0]

    It appears to look at the first number and orders them that way

    10
    12
    3
    5
    9

    Is there something additional that might I’m missing?

  • Dan Ebberts

    September 19, 2017 at 5:29 pm

    Try this in a text layer so you can see what it does:

    a = [12,5,9,10,3];
    a.sort(function(a, b){return a – b});
    a.toSource();

    Dan

  • Scott McGee

    September 20, 2017 at 6:41 pm

    That worked a charm.

    Thank you very much.

    Now too complicate things.

    Is there a way.

    a = [12,5,9,10,10,3];
    a.sort(function(a, b){return a – b});
    a.toSource();

    Like above, say you have 2 of the same number in an array. It’s not so much of an issue for this example, but what I want to finally do. If two numbers are the same, it will look at a secondary number to determine which 10 in this case goes in order of the other.

    Is it possible to if([]&&[] ==true) look at another part to determine which goes above the other.

    All I can think is. Split

    A = 10-9
    B = 10-5

    If[A.split(“-“)[0] == B .split(“-“)[0]) {
    C = [A.split(“-“)[1],B.split(“-“)[1]]
    C.sort(function(a, b){return a – b});
    } else {
    C = [A.split(“-“)[0],B.split(“-“)[0]]
    C.sort(function(a, b){return a – b});
    }

    I know this probably isn’t right without testing, but it looks right in my head…But too do this with 24 numbers would break my head.

    If there is no easy way…I’m just going to leave it and say I can’t build this. Spend some money get an API from Press association rather than trying to do this cheap and expecting someone to fill 144 boxes of Data.

    At least to fill Wins, Draws and Goal Difference, at least reduces this, but the poor sod has to do this weekly for 2 sports and 6 leagues in each of them. So I’m hoping I can build something that will alter text.sourceText from above expression. POINTS-GD-W-D-L-TEAM Then whatever the order the array sorts…It puts the rest of the data into the other fields.

    The theory works, it’s just now if Points are the same it looks at GD instead.

    I’ll have one comp that they type the data in and comp two is the MASTER.

    I know I’d be best writing a script, but it’s time more than anything.

  • Obed Ampong

    September 22, 2020 at 1:21 am

    Hi

    I tried this expression in AE CC2020 but I got a syntax error in line 2. Is there any way out?

    Thanks

    Obed

  • Obed Ampong

    September 22, 2020 at 8:23 am

    Hi Dan,

    Please, I need your help. I tried this expression AE CC 2020 but I got a syntax error in line 2.

    Thanks.

    Regards,

     

    Obed

     

  • Dan Gehin

    October 29, 2021 at 3:50 pm

    Hey Obed, I had the same issue, this seems to work for me:

    a = [12,5,9,10,3];
    a.sort((a,b)=>a-b)

Viewing 1 - 8 of 8 posts

Log in to reply.

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