1
\$\begingroup\$

So I'm setting up social leaderboards and I want there to be daily weekly overall high scores. The way the scoring works is each score is tied to a user after the user logs in so the scores need to always be linked to a user. I'm using the Parse BaaS with Unity C# and I've gotten overall highscores working by adding a highScore field to the ParseUser model. From the research that I've done so far based on google play services and game center has led me to the following solution.

Have 3 fields for the ParseUser model: overallScore, dailyScore, weeklyScore. Reset dailyScore and weeklyScore when appropriate

Is this an appropriate solution for what I'm trying to implement? Is there a more efficient or scalable way to do it?

\$\endgroup\$
  • \$\begingroup\$ Why not try it and find out? In general if you try it and it works then it was a good solution. Try not to analyse the future-proofing too much or you'll never end up developing any features. \$\endgroup\$ – Tom 'Blue' Piddock Oct 13 '15 at 9:40
0
\$\begingroup\$

I think its better to have score submission time stamp associated with each score, so that you don't have to rely on resetting the score at the weekend or day end.

So basically the structure will have following fields

  • User id
  • OverallScore
  • Weekly Highscore
  • Weekly Highscore Timestamp
  • Daily Highscore
  • Daily Highscore Timestamp

Now lets consider the working , the user submits a score to the backend.

  • For weekly highscore check if the timestamp in the database is older than the current week.
    • If YES, then replace the score with the newly submitted value straight away.
    • If NO , then compare the stored and submitted value
      • if stored value is greater then do not update the field
      • if stored value is smaller then store the new value and update the timestamp

Same procedure repeat for the daily highscore :)

To fetch the weekly highscore you need to query looking for the timestamp which belongs to the current week and order in descending order according to the score. Same for daily.

I usually follow this approach as its robust and doesn't depend on any kind of cron job or task scheduler for resetting the scores (which sometimes might not run and end up messing the result)

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks so much for your answer Hash! I like this solution and I'd like to know should I put this in the user model itself to be more convenient or should I create a separate model for it for encapsulation say a Streak model? \$\endgroup\$ – chosendeath Oct 13 '15 at 15:52
  • \$\begingroup\$ I am sorry can't answer that , as I did this in PHP and SQL and it was just one table. \$\endgroup\$ – Hash Buoy Oct 13 '15 at 16:01
  • \$\begingroup\$ Ok one more question so I've implemented your solution and I'm worried about timezones. Is storing utc times in order to make sure everyone resets at the same time? \$\endgroup\$ – chosendeath Oct 15 '15 at 15:45
  • \$\begingroup\$ Yes Of course ... UTC should be the timezone, so while submitting the highscore the user doesn't need to send the time information. The server takes the current UTC and stores it in the table. \$\endgroup\$ – Hash Buoy Oct 15 '15 at 16:18
  • \$\begingroup\$ And there is no actual reset in the method i have described. It just queries for the entries belonging to the current day or week. The old entries will still be there but just wont get selected as they wont belong to the current time frame. \$\endgroup\$ – Hash Buoy Oct 15 '15 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.