Sign In Register

How can we help you today?

Start a new topic

Removing player from partitioned leaderboard

So leaderboard partitions are pretty slick - using it so that each player 'level' essentially gets its own leaderboard - so when I send in the appropriate event with win/loss data, one of the event params is the player level - which updates their data on the correct leaderboard partition.  YAY!.


Except - a player can change level during the leaderboard 'period'.

When that happens, the player ends up showing up in multiple partition.

While I can pinpoint when a player level changes, I can't seem (from a pure cloud-code perspective) seem to get a list of leaderboards that this player exists within to then delete them from the 'old' partition (using  deleteEntry).


Thoughts?  This seems like it would be a common use-case, so I wonder if I am not missing something obvious.


thanks in advance!


If there is a way that will auto-magically ensure a player appears in only one partition, that would be MCH better than trying to remove entries....but I don't see anything obvious

Hi Jeff,


There is no way to magically make this happen I'm afraid, when you post to a leaderboard you could store a reference to the partition the player posted to in the players scriptData. Then if they post a score to another one, check the scriptData for the shortCode they are currently in and then delete the entry from there. Then add the new partition they are in to scriptData and repeat for each score that is posted. Does that sound like it might work for you ?


Thanks,

Liam

Possibly - except I couldn't seem to locate a non-deprecated way to delete a player entry from a leaderboard - thoughts?

bump

Hey Jeff,


Apologies for the delayed response, you can delete an entry for a player in a leaderboard with the following.


var leaderboard = Spark.getLeaderboards().getLeaderboard(lb_ShortCode);
leaderboard.deleteAllEntries(playerId, true)

 

Try that out and let me know how you get on.


Thanks,

Liam





Docs state "This method only works for realtime leaderboards" (which this is not)...

thoughts?

https://docs.gamesparks.com/api-documentation/cloud-code-api/leaderboards/sparkleaderboard.html

Also - this will remove the player from previous day/month partitions - which might be used for legacy reporting.  Any way to remove player from a specific partition?

Hi Jeff,


Apologies, I assumed you were using a real time board. I'll find out how to do this for you. I believe deleteEntry was how this was done before but as it seems to be deprecated now I'll confirm the correct way for you. As each leaderboard snapshot/partition is essentially its own leaderboard you would need to remove the entry on each individual one. You could use SparkLeaderboards "isPartitioned" to check if the current leaderboard is partition and if it is use "getPartitions" to return an array of those partitions. You can then use this array to check for entries from a player on each of them and remove them if you wish.


Thanks,

Liam

Thanks Liam - but even if I got the partitions that a player is in - the only way to delete entries is deleteAllEntries which has the comment about realtime only....

Hi Jeff, 


The method shared above will work on Real Time and Reset Leaderboards only. Currently there is no way to remove an entry from a static Calculated Leaderboard. You can drop a calculated leaderboard with the following

  

var LB = Spark.getLeaderboards().getLeaderboard("LB_shortCode").drop()

  

If you'd like to hide a player on leaderboards you can read about how to do that here. If you can tell us a bit more about your leaderboard configuration and what exactly you'd like to achieve with it we can help you get it configured.


Thanks,

Liam



In this case - it's a reset leaderboard (so hopefully this will work for me!)


It's a case where I need (for example) weekly leaderboards (they reset weekly) but broken out by player 'level'.

(there are other leaderboard attributes like score, wins, losses, etc).

The player level can change mid-week - so I need to ensure that they exist ONLY in one partition.



Hi Jeff,


This should work fine if it's a Reset Leaderboard. You just need to find the right point to trigger the deleteAllEntries call to remove the player entry from a previous partition. When posting the score to a leaderboard you could set the level attribute to the players scriptData. Then in the Cloud Code of the postScore event you can get this value and check the partition for a score and if one is there remove it. If the score posted triggers a NewHighScoreMessage you could also run the code for removing a previous entry in there. If you have any further questions just let me know.


Thanks,

Liam

Actually I would do the removal on the code that fires off the postScore event (as I know if that critical player level value has changed) - but yeah - that is the plan.    Thanks for the input - I'll post if things go awry!



Hi Jeff,


No problem, let us know if you need anything.


Thanks,

Liam

Login to post a comment