Step 3. Write leader board events sheet
-----------------------------------------------------------
Change to <e_leaderBoard> and write the following instructions:
Event#1 triggers on start of layout. It ask [LeaderBoard] plugin to get player score according to Auth.UserID. We do this because - we don't want a new lower score to cover another previous higher score. For example, if your last glory score was 1000 points but this time you are screwed and get only 100 point, then you shouldn't upload this shameful score to overwrite the former. So it's important to read your last score 1st, and then see what to do for the next.
Event#2~4 triggers when we get our last score.
Event#3 compares the new score with LeaderBoard.LastScore. If the new score is higher, we post new score to backend database; Otherwise we should post nothing and just request data from backend database ( here request for top 10 scores only).
Event#5 triggers when post new score is complete. It means our new score was written and now we can request data from backend database ( here request for top 10 scores only).
Global number temp_loopindex serves as the loopindex value for the <for each rank> event below. We will explain later.
Event#6~9 triggers when we receive top 10 leader board from backend database. First we destroy the "loading..." text and clear temp_loopindex to 0. Then we use a <For each rank> event to process each received record. What we have to is - if player is on top 10 list, then make his record shown in red to highlight his score. So in each loop we compare LeaderBoard.CurUserID (the owner of the current score) with Auth.UserID (the id of logged-in player). If they are equal then we create one text line on screen and turn it to red, and show his rank, name, and score respectively. Otherwise we do the same thing without turn the text to red. At the end of each loop we add 1 to temp_loopindex, this affects the position of the next line to be created.
Event#10 triggers when player clicks the "Replay" button. It just go back to <layout 1>.
OK! Now push <F4> to run the layout, go get some coins and drop off screen, you should see your glory high score is highlighted in red on your own Parse leader board.
Hope you'll like this tutorial and I'm giving a big shout out to rexrainbow.
See you next time!