I have a problem with leaderboards. Let's see if I manage to explain it well: - I have two Events (Score1 and Score2), each of them has one attribute (SCORE1 AND SCORE2).
- I have three leaderboards that have to be sorted by these two events as follows: - Leaderboard1 is sorted by SCORE1. - Leaderboard2 is sorted by SCORE2.
- Leaderboard3 is sorted by the result of this calculation: SCORE1 + SCORE2.
I know how to manage Leaderboard1 and 2, but I don't know how or where to calculate the sum. I've tried with cloud code, but I don't know how to access, from one event, variables of another event.
Thank you!
Best Answer
C
Customer Support
said
almost 7 years ago
Hi Javier,
What you could do is set up a third Leaderboard and event, then place some code in the SCORE1 and SCORE2 events that will take any score posted by either event and post them to Leaderboard 3 for you. So what you can do is set up another event called "SCORE3", then create a new Leaderboard called Leaderboard3 which uses the "SCORE3" number attribute set to "SUM". Next navigate to Cloud Code and open up the events "SCORE1" and "SCORE2", when these are open place the following code into both.
//this will get the score passed in from SCORE1 and SCORE2
var score = Spark.getData().score;
//now we'll use SparkRequests to send the SCORE3 event using the scores from SCORE1 & SCORE2
var request = new SparkRequests.LogEventRequest();
request.eventKey = "SCORE3";
request.SCORE3 = score;
var response = request.send();
Now when you post to Leaderboards 1 & 2, the scores will automatically be sent to Leaderboard 3 and added together for you. If you navigate to the manage screen and click into Leaderboards you'll see something like below.
On the first Leaderboard I posted a score of 70
On the second Leaderboard I posted a score of 15
My third Leaderboard has the scores from both added together automatically by using the Cloud Code in the Score events for Leaderboard 1 & 2
Hope this helps, if you have any further questions just let me know.
What you could do is set up a third Leaderboard and event, then place some code in the SCORE1 and SCORE2 events that will take any score posted by either event and post them to Leaderboard 3 for you. So what you can do is set up another event called "SCORE3", then create a new Leaderboard called Leaderboard3 which uses the "SCORE3" number attribute set to "SUM". Next navigate to Cloud Code and open up the events "SCORE1" and "SCORE2", when these are open place the following code into both.
//this will get the score passed in from SCORE1 and SCORE2
var score = Spark.getData().score;
//now we'll use SparkRequests to send the SCORE3 event using the scores from SCORE1 & SCORE2
var request = new SparkRequests.LogEventRequest();
request.eventKey = "SCORE3";
request.SCORE3 = score;
var response = request.send();
Now when you post to Leaderboards 1 & 2, the scores will automatically be sent to Leaderboard 3 and added together for you. If you navigate to the manage screen and click into Leaderboards you'll see something like below.
On the first Leaderboard I posted a score of 70
On the second Leaderboard I posted a score of 15
My third Leaderboard has the scores from both added together automatically by using the Cloud Code in the Score events for Leaderboard 1 & 2
Hope this helps, if you have any further questions just let me know.
Thanks,
Liam
J
Javier Garrigues Tudela
said
almost 7 years ago
Hi Liam, Thank you very much for the answer, it seems to be exactly what I need. I'll let you know if I have any problems.
Javier Garrigues Tudela
Hi there,
I have a problem with leaderboards. Let's see if I manage to explain it well:
- I have two Events (Score1 and Score2), each of them has one attribute (SCORE1 AND SCORE2).
- I have three leaderboards that have to be sorted by these two events as follows:
- Leaderboard1 is sorted by SCORE1.
- Leaderboard2 is sorted by SCORE2.
- Leaderboard3 is sorted by the result of this calculation: SCORE1 + SCORE2.
I know how to manage Leaderboard1 and 2, but I don't know how or where to calculate the sum. I've tried with cloud code, but I don't know how to access, from one event, variables of another event.
Thank you!
Hi Javier,
What you could do is set up a third Leaderboard and event, then place some code in the SCORE1 and SCORE2 events that will take any score posted by either event and post them to Leaderboard 3 for you. So what you can do is set up another event called "SCORE3", then create a new Leaderboard called Leaderboard3 which uses the "SCORE3" number attribute set to "SUM". Next navigate to Cloud Code and open up the events "SCORE1" and "SCORE2", when these are open place the following code into both.
Now when you post to Leaderboards 1 & 2, the scores will automatically be sent to Leaderboard 3 and added together for you. If you navigate to the manage screen and click into Leaderboards you'll see something like below.
On the first Leaderboard I posted a score of 70
On the second Leaderboard I posted a score of 15
My third Leaderboard has the scores from both added together automatically by using the Cloud Code in the Score events for Leaderboard 1 & 2
Hope this helps, if you have any further questions just let me know.
Thanks,
Liam
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Javier,
What you could do is set up a third Leaderboard and event, then place some code in the SCORE1 and SCORE2 events that will take any score posted by either event and post them to Leaderboard 3 for you. So what you can do is set up another event called "SCORE3", then create a new Leaderboard called Leaderboard3 which uses the "SCORE3" number attribute set to "SUM". Next navigate to Cloud Code and open up the events "SCORE1" and "SCORE2", when these are open place the following code into both.
Now when you post to Leaderboards 1 & 2, the scores will automatically be sent to Leaderboard 3 and added together for you. If you navigate to the manage screen and click into Leaderboards you'll see something like below.
On the first Leaderboard I posted a score of 70
On the second Leaderboard I posted a score of 15
My third Leaderboard has the scores from both added together automatically by using the Cloud Code in the Score events for Leaderboard 1 & 2
Hope this helps, if you have any further questions just let me know.
Thanks,
Liam
Javier Garrigues Tudela
Thank you very much for the answer, it seems to be exactly what I need. I'll let you know if I have any problems.
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics