Sign In Register

How can we help you today?

Start a new topic
Answered

Wins and Losses on Leaderboard

We are trying to set up a leaderboard that tracks players' scores per in-game region, and also tracks their wins and losses. We are hung up on exactly how to configure our leaderboard and running totals.

The game world is divided into several locations, each which contain multiple levels. Each location should have a leaderboard, and scoring is based on the sum of the players' best score for each level in that location. The leaderboard also tracks each player's wins and losses but they should not factor in the ranking.

For example, let's say John is in the 'Fire World' location where he has completed three levels. His best score for level 1 is 100 points, his best score for level 2 is 50 points, and his best score for level 3 is 25 points. Therefore his total score on the 'Fire World' leaderboard is 175 points. John's score in other locations would not be affected by his score in 'Fire World', and vice-versa.

This is our current Leaderboard configuration:

Event: End of Level
    Attributes:
  • Score, Number, Maximum
  • Location, String, Grouped 
  • Level, Number, Grouped
  • Win, Number, Count //0 or 1

Running Total:
    Group: Location, Level Number
    Attributes:
  • Score, Maximum
  • Level Number, Supplemental
  • Location, Maximum    //for partitioning
  • Score, Count, <=, 0    //this was intended to track losses but does not work
  • Win, Count, >, 0        //this was intended to track wins but does not work


Leaderboard:

  • MAX-SCORE, Desc, Sum
  • MAX-LOC, None, Partition
  • COUNT-SCORE, None, Sum //this is supposed to be the number of times the player has lost
  • COUNT-WIN, None, Sum  //this is supposed to be the number of times the player has won


This setup lets us track the sum of the player's best scores for each level, partitioned by location, but does not track wins and losses correctly. The filters don't seem to work with a COUNT summary, so COUNT-SCORE and COUNT-WIN both have the same value: the number of times the player has played (won or lost) a level.


How can we track wins and losses correctly?


Best Answer

Hi Joeseph,


Yes, count would be the wrong type to use here. That will just increment by one when the event is sent. I think you need to set you the win attribute in your event to SUM. Then when sending the event you would pass 1 for a win and 0 for a loss. Placing 0 here just means the number won't change. You could also use -1 if you wanted to reduce the number (if that suited your needs, it may now). I don't think you need the custom running total here. You should be able to do this with a single event and two leaderboards. I've set the event up like yours. I'm using SUM but you can use Maximum if you wish.


image


Then I have my worldScoreTotal_LB leaderboard set up like this. It's going to add all the scores together for that world for all of the levels.


image


My individual partitioned leaderboard looks like this. It will partition by level and location and also track wins.


image



Now we can test this. We'll use FireWorld as an example.


//player scores 50 on level 1

{

 "@class": ".LogEventRequest",

 "eventKey": "worldScoreTotal",

 "score": 50,

 "location": "Fireworld",

 "level": 1,

 "win": 1

}


//player then scores 50 again but on level two

{

 "@class": ".LogEventRequest",

 "eventKey": "worldScoreTotal",

 "score": 50,

 "location": "Fireworld",

 "level": 2,

 "win": 1

}


As a result of this the player will have scores on 3 leaderboards.


On the partition "worldScoreTotal_Partition.level.1.location.Fireworld" with a score of 50 and win count of 1

On the partition "worldScoreTotal_Partition.level.2.location.Fireworld" with a score of 50 and win count of 1

On the partition "worldScoreTotal_LB.location.Fireworld" with a score of 100 (combined score from both levels)


Is this the functionality you require here ? It seems pretty close but if I've missed something just let me know. 


Thanks,

Liam



 


Answer

Hi Joeseph,


Yes, count would be the wrong type to use here. That will just increment by one when the event is sent. I think you need to set you the win attribute in your event to SUM. Then when sending the event you would pass 1 for a win and 0 for a loss. Placing 0 here just means the number won't change. You could also use -1 if you wanted to reduce the number (if that suited your needs, it may now). I don't think you need the custom running total here. You should be able to do this with a single event and two leaderboards. I've set the event up like yours. I'm using SUM but you can use Maximum if you wish.


image


Then I have my worldScoreTotal_LB leaderboard set up like this. It's going to add all the scores together for that world for all of the levels.


image


My individual partitioned leaderboard looks like this. It will partition by level and location and also track wins.


image



Now we can test this. We'll use FireWorld as an example.


//player scores 50 on level 1

{

 "@class": ".LogEventRequest",

 "eventKey": "worldScoreTotal",

 "score": 50,

 "location": "Fireworld",

 "level": 1,

 "win": 1

}


//player then scores 50 again but on level two

{

 "@class": ".LogEventRequest",

 "eventKey": "worldScoreTotal",

 "score": 50,

 "location": "Fireworld",

 "level": 2,

 "win": 1

}


As a result of this the player will have scores on 3 leaderboards.


On the partition "worldScoreTotal_Partition.level.1.location.Fireworld" with a score of 50 and win count of 1

On the partition "worldScoreTotal_Partition.level.2.location.Fireworld" with a score of 50 and win count of 1

On the partition "worldScoreTotal_LB.location.Fireworld" with a score of 100 (combined score from both levels)


Is this the functionality you require here ? It seems pretty close but if I've missed something just let me know. 


Thanks,

Liam



 

Thanks for the reply and assistance. A couple of things:


1. The third screenshot you posted is the same as the first screenshot. From the description it sounds like it should be a different one.

2. We need to be able to track wins and losses separately and show them on the same leaderboard. Does your solution only tracks wins?


Thanks!

Okay, I believe we have a solution that does exactly what we need now. Thanks again for your assistance; I'll follow up if I have any more questions.

Hi Joseph,


You're right. I've just fixed the image. Let me know if you need anything else.


Regards,

Liam

It occurs to me now that we can calculate losses by tracking wins and attempts, and subtracting wins from attempts.


Part of the reason we've struggled with the Leaderboards is that the documentation is scattered and some of it seems to contain mistakes. The only tutorial that creates a running total doesn't use that running total (see https://docs.gamesparks.com/tutorials/social-features/creating-time-based-leaderboards.html ; the screenshot for step 3 does not use the running total created in step 2). It would be great if that could get cleaned up and expanded a bit!

I'm still seeing the same screenshot in that tutorial. Maybe it didn't get saved after you changed it? It also has the wrong formula under "filter value"; it does not match the formula in the text.

Hi Joseph,


It has been changed, try clearing your cache and refreshing the page.


Thanks,

Liam

Login to post a comment