Skip to main content
Participant
November 15, 2024
Answered

Creating a dropdown menu for a 5-star rating

  • November 15, 2024
  • 1 reply
  • 461 views

Hi there,

 

I am a complete fool when it comes to expressions and have been looking for something to create a dropdown menu for selecting a star rating (1-5 stars). I'm setting up a mogrt for the client to easily pick the desired rating. The idea is to have dropdown item 1 > select 0 stars. Item 2 > selecting star 1. Item 3 > selecting both star 1 + 2 and so on. 

 

Currently I ended up with this expressions (from a nice blogpost by Sharayash Sherestha):

menu_value = thisComp.layer("Dropdown Menu").effect("Dropdown Menu Control")("Menu"); if (menu_value == index) 100; else 0;

 

Instead of the index I use the item numbers. I figured I could add multiple numbers at "index" (seperated by comma's?) to let the layer's opacity know it can be at 100% for all of those. That didn't work. 

Thanks in advance for any help! 

Correct answer Airweb_AE

Maybe like this: 

thisComp.layer("CONTROLS").effect("Rating")(1) > name.split(' ')[1] ? 100 : 0

 

1 reply

Airweb_AECorrect answer
Legend
November 15, 2024

Maybe like this: 

thisComp.layer("CONTROLS").effect("Rating")(1) > name.split(' ')[1] ? 100 : 0

 

Participant
November 15, 2024

Exactly what I was looking for, works like a charm! Thank you very much for taking the time to create this!! 

 

If you don't mind me asking, could you perhaps give a basic explanation as to how this is working exactly? I'd like to improve my understanding of this stuff. If not, no worries! 

Legend
November 15, 2024

It might be clear:

 

// Example: 
// name = "Full 1"
// name.split(" ") splits the string into an array ["Full", "1"]
// name.split(" ")[0] retrieves the first element: "Full"
// name.split(" ")[1] retrieves the second element: "1"
// The condition compares the "Rating" effect value with the second part of the name.
if (thisComp.layer("CONTROLS").effect("Rating")(1).value > name.split(" ")[1]) {
  100; // If the "Rating" value is greater, output 100
} else {
  0;   // Otherwise, output 0
}