Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Combing Loops, If/thens, indexes, and list ordering….

Tagged: 

  • Combing Loops, If/thens, indexes, and list ordering….

    Posted by Ryan Hauser on May 26, 2024 at 9:59 pm

    I can figure out if/thens and loops on their own, but combining them together into a single expression is something I can’t quite figure out.

    I’m attempting to create a dynamic initiative tracker for a D&D podcast. I’ve gotten all of the expressions sorted out, except for one: Sort their initiative rolls (the number on the left) from highest to lowest. I know the method I want to use, but it’s the execution that I’m struggling with.

    The method I’d like to use is fairly straight forward. I have N number of combatant layers above a null named “loopCount”. By referencing loopCount’s layer index, I’ll be able to dynamically determine the number of combatants, and thusly the number of loops I’ll need to execute. Each combatant layer will have a slider property called smallerNumbers. I’ll be taking each layer’s “initiativeRoll” slider property, and looping through the initiativeRoll property for every combatant layer. For every layer that this layer’s initiativeRoll property is larger than, increment this smallerNumbers’ value by 1. Once I know how many other rolls this layer’s initiative is larger than, I’ll just multiply the the smallerNumber result by some constant number, and add it to the layer’s Y position. Theoretically, this should have the list visually sorted in the composition… Possibly in reverse, but that’s a problem for later.

    This method does mean that identical initiative rolls won’t ‘see’ each other and sort properly, so ideally I’d also like it to kick back an error notification if there’s duplicate initiative rolls.

    It’s so frustrating to know what I want to do, but just not knowing the syntax to get it working how I want.

    Ryan Hauser replied 1 year, 11 months ago 1 Member · 1 Reply
  • 1 Reply
  • Ryan Hauser

    May 27, 2024 at 1:08 am

    I’ve gotten it figured out! Here’s my code…

    largerThan = 0;

    myRoll = essentialProperty("Initiative Roll");

    loopCount = thisComp.layer("LoopCount Index").effect("LoopCount")("Slider")-1;

    myIndex = index;

    loopCountTrueIndex = thisComp.layer("LoopCount Index").effect("LoopCount")("Slider");

    distanceToController = loopCountTrueIndex - myIndex;

    distanceToTop = myIndex -1;

    for(i = 0; i < loopCount; i++){

    if (myRoll < thisComp.layer(index-distanceToTop).essentialProperty("Initiative Roll"))

    {largerThan = largerThan + 1}

    else

    {}

    distanceToTop = distanceToTop -1;

    }

    [largerThan];

    I haven’t yet added that error condition when two initiative rolls are the same, but functionally it works as it should! If anyone knows how I’d add that I’d still appreciate it.

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