Sign In Register

How can we help you today?

Start a new topic

Can I update all leaderboard entries via cloud code?

I'm writing a game where players make predictions about certain events (sometimes long-term, a few days or months in advance), I save all of their answers to the individual players player data. It's in their script data, question number and answer choice like this withing their player data:


 "scriptData": {

  "question": "5,4",

  "choice": "1,2"

 },



However once the event plays out and the predictions are proven either true or false I need to award them with points.  


I'd like to be able to go through each player 1 at a time, compare their question+answer combos to my list of questions+answers and then award points (in the form of increasing their score on the leaderboard).  


Is there a way I can loop through every player and update their leaderboard score via Cloud Code? I don't have much javascript experience.


Hi Keegan,


It probably wouldn't be a great Idea to loop over the player collection to update scores for them in one go. If a player has score related data that is stored in scriptData you could check it at a time that suits you and then compare their answers and generate a score. You could create a meta collection for your games answers and then compare the players stored answers against that. Some code in your AuthenticationResponse could work here. You could check a date here and see if it's time to check this users answers and post the score to the leaderboard. This way you'll only be updating data for active players. Does that sound like it might work for you ? 


Thanks,

Liam

 

Some code in your AuthenticationResponse could work here. You could check a date here and see if it's time to check this users answers and post the score to the leaderboard. This way you'll only be updating data for active players. 

 

I like this idea, my only reasoning for wanting to loop through them all initially is that in the best case scenario I'd want all players scores to be updated at the same time (or around the same time), for example If I could update every players score that needs updating at say midnight each day.  


My reasoning for this is that the way the game will work players will be answering a handful of questions, potentially earlier in the week/day, and I'd like to update everyone's scores when the result of the question is revealed.  


The correct answer isn't known to anyone including myself before hand, so I can't just assign people points as they answer it. For example it could be asking something like "Will the Chicago Bears win on Sunday?". Once the game is over and the Bears have either won or lost I'd like to update the leaderboards for EVERYONE who submitted an answer for that question, so that the leaderboards are always up to date, and there aren't any surprises when someone who maybe hasn't logged in to the App in a few days all of a sudden has their score updated upon authenticating, and shoots up in the leaderboards when their score is updated.  


Are you suggesting not looping through the entire player collection each time because it'd be extra strain on the servers? or because it'd be slow?


Essentially I'd just like to update all players scores at 12:00 midnight to reflect any questions that have been answered each day if possible. If that isn't feasible I do like your idea of doing something in the AuthenticationRespone, I'm just not sure yet what I'd want to do to handle players who don't sign in for a few days.

Not sure if "bumping" of topics is allowed or not, sorry if it isn't, but I'm still curious if there's any reasonable way I can update all users leaderboard scores based on values in their player objects at a given time, rather than only upon them logging in.

Hi Keegan,


A bulkjob might be useful here if you really needed to update them all around the same time. You can read more about bulkJobs here. If you have any questions just let us know.


Thanks,

Liam

Login to post a comment