Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating a dropdown menu for a 5-star rating

Community Beginner ,
Nov 15, 2024 Nov 15, 2024

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! 

TOPICS
Expressions
475
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Nov 15, 2024 Nov 15, 2024

Maybe like this: 

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

screenshot.png

 

Translate
Advocate ,
Nov 15, 2024 Nov 15, 2024

Maybe like this: 

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

screenshot.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 15, 2024 Nov 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! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 15, 2024 Nov 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
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 15, 2024 Nov 15, 2024
LATEST

Incredibly helpful, I take my hat off and bow for you. Thanks a lot! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines