ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Numerical order

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
Numerical order
on Sep 18, 2017 at 1:18:51 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.


Return to posts index

Scott McGee
Re: Numerical order
on Sep 18, 2017 at 7:50:19 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=104019...


Return to posts index

Scott McGee
Re: Numerical order
on Sep 19, 2017 at 7:32:06 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?


Return to posts index


Dan Ebberts
Re: Numerical order
on Sep 19, 2017 at 5:29:04 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



Return to posts index

Scott McGee
Re: Numerical order
on Sep 20, 2017 at 6:41:04 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.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]