Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Enter a Score and work out its postion?

  • Enter a Score and work out its postion?

    Posted by Dave Martin on July 31, 2013 at 9:30 pm

    Here’s a challenge for ya…

    I’m building a scoreboard and i’d like to have the postion of the contestant worked out based on their score

    So, say I have these variables;
    Name1 = [score]
    Name2 = [score]
    Name3 = [score]
    Name4 = [score]

    How can I work out the postions (1st, 2nd, 3rd, 4th,…) based on the scores?
    I would like an expression to return values of 1, 2, 3, 4,… Which i will use to change the Y position of a pre Comp in the main comp.

    I’ve got loads of these boards to do so was hoping I could just build one. Duplicate it, Enter the scores and have the contestants re-ordered automatically 🙂

    Cheers

    Walter Soyka replied 13 years ago 2 Members · 1 Reply
  • 1 Reply
  • Walter Soyka

    August 1, 2013 at 12:30 pm

    Here’s an expression that may help you. Be sure to read the comments and do something with the value at the end:

    // scores go here!
    scores = [300,800,200,500,0,500];

    // create a new array of arrays which will hold hold the scores and their original index in the array.
    scoresIndices = new Array(scores.length);
    for (i = 0; i < scores.length; i++) scoresIndices[i] = [scores[i],i];

    // sort the array, like magic
    scoresIndices.sort(function(a,b) {return b[0] - a[0]});

    // finally, you can get the indicies in sort order. The first will be scoresIndices[0][1], the second will be scoresIndicies[1][1]
    // the third will be scoresIndices[2][1] and so on
    scoresIndices[0][1]

    Walter Soyka
    Principal & Designer at Keen Live
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    RenderBreak Blog – What I’m thinking when my workstation’s thinking
    Creative Cow Forum Host: Live & Stage Events

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