Making a Functional Star Rating Using Components
In this lesson, you will learn how to make a star rating panel for your prototype using components & variables.
![Tianyang Wang](https://cdn.sanity.io/images/qyzm5ged/blog/6555bcb753c155e700557c75366bc50854d3bd2f-120x120.jpg/Tianyang-Wang-Monash-University-Design-Student.jpeg)
![Star Rating Using Components Thumbnail](https://cdn.sanity.io/images/qyzm5ged/blog/025496c2884fd0f151958f65dfb244369f6acc71-2138x1200.png/Star-Rating.png)
Introduction
Star rating is usually used to gain relevant feedback from users on how they engage with the app content. It acts as a visual review for your app. However, implementing the star rating function can be quite tedious. There are multiple ways to do it but some methods can be manually exhausting. With ProtoPie, you can build a star rating functionality within minutes without any hassle. This tutorial will cover how this effect can be achieved using components, variables, and send & receive.
What you'll learn
- Give each component instance a special number to set its unique identity
- Using the unique identity to light up the current and previous stars on tap
In the end, you’ll be able to make something like this!
![Star Rating Prototype Made With ProtoPie](https://cdn.sanity.io/images/qyzm5ged/blog/23d3b98055a0746bb77010e000feaa4439f6d9d6-375x375.gif/Screen-Recording-(ProtoPie).gif)
Step by step instructions
Give each component instance a special number to set its unique identity
1. Open the "Star" component.
Once you have created a star component, make 5 instances of it in your working scene. Once done, open your main Star component.
💡 Why use components?
We use components when we have objects with similar behaviors. In this case, all 5 stars have similar behaviors. Using components may also avoid redundant and tedious work of adding triggers/ responses to your interactive objects over and over again.
2. Add a "number" variable for the "Star" component.
The next step is to add a number variable to the Star component. We'll make sure that the Make Overridable option is ticked for this variable. We do this so that we can set a unique identity to the individual Star child instances.
![Add a "number" variable for the "Star" component.](https://cdn.sanity.io/images/qyzm5ged/blog/252a8b5aa2305fb3d1c2c4847083333e9c25d86d-1389x872.gif/Screen-Recording-(ProtoPie).gif)
💡 What's make overridable?
Make overridable means every instance of a component can have a different initial value with the variable. In this case, we use it for setting a unique identity for every child component.
After ticking the Make Overridable option, go back to the main working scene and change the individual Star child instance numbers from (1 to 5) in an orderly manner. This sets a unique identity to each Star child instance.
![Change the individual Star child instance numbers from (1 to 5)](https://cdn.sanity.io/images/qyzm5ged/blog/ff4393402b91692c3412a7255160063e6b6d7379-432x634.png/image.png)
Using the unique identity to light up the current and previous stars on tap
1. Add a Tap trigger and a Send response to the "Star" component.
 a. Now go back to the main Star component. We want a certain response once the stars are tapped. So we will add a Tap trigger. Under the Tap trigger, add a Send response.
![Under the Tap trigger, add a Send response.](https://cdn.sanity.io/images/qyzm5ged/blog/36845bc122ba6801b466b3523435e21abc918379-858x178.png/image.png)
 b. Set the message under response as "tapped". This indicates that the star instance is being tapped. We will tick the Send Value Together option and set the value as the "number" variable. Doing this will store the number of the Star child instance which is being tapped.
![Tick the Send Value Together option and set the value as the "number" variable](https://cdn.sanity.io/images/qyzm5ged/blog/a6487d0c79fa9b0b1cb73cc0c5d477541e345ca1-434x720.png/image.png)
💡 Where is the message sent to?
The message is sent to all the "Star" instances in the main scene, including the tapped "Star" instance.
2. Add a Receive trigger to the Star component and create another variable called "tapped_number".
 a. After setting up the Send response, we want to receive some response from the tapped Star instance. So let's create a variable first and name it "tapped_number".
![Create a variable first and name it "tapped_number"](https://cdn.sanity.io/images/qyzm5ged/blog/c1b8cf4bb90ab5f9185a509d8ce6dd95d181a422-432x364.png/image.png)
 b. Add a Receive trigger and set the message as "tapped", and tick the Assign to Variable option. Choose the tapped_number as the variable to assign. This returns the value of the number of the Star instance in the main scene which is tapped.
![Add a Receive trigger and set the message as "tapped"](https://cdn.sanity.io/images/qyzm5ged/blog/a0b0b167a00881086a4ca1d61000c560721a0a12-936x554.png/image.png)
3. Lighting up current and previous stars on tap.
 a. Add a condition under the Receive trigger. Set the condition as number ≤ tapped_number
. Under the condition add a Color response on the Vector layer. Set the Fill of the color response to #FDC97D (the color may vary according to your prototype). This will ensure that the "Star" instances before the tapped "Star" instance change their color.
![Set the condition as number ≤ tapped_number](https://cdn.sanity.io/images/qyzm5ged/blog/4375a50f1af3f28e526103ea5f85fffc87370751-1094x368.png/image.png)
 b. Add another condition under the Receive trigger. Set the condition as number > tapped_number
. Add a Reset response on the Vector layer. This will ensure that the "Star" instances after the tapped "Star" instance don't change their color.
![Set the condition as number > tapped_number](https://cdn.sanity.io/images/qyzm5ged/blog/e71fe017f837f31ff8711b95cd72d7610bdf6999-1088x614.png/image.png)
💡 How does it work?
While tapping a Star instance, the Star instance will send a message to update the other Star instances whether they should be lighted up or not.
Congratulations!
Good job on following through the steps. It's pretty simple and straightforward, right? Making a star rating with ProtoPie is like a piece of cake. Try it out for yourself.