Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement internet high scores in Google App Engine
    text
    copied!<p>I want to implement internet high scores for my game. And give feedback to players which place they have (not only top100 or something like that). In normal SQL it would look like that:</p> <p>SELECT COUNT(*) FROM Scores WHERE points > :newUsersPoints</p> <p>and GQL have something similar</p> <p>db.GqlQuery("SELECT * FROM Score WHERE points > :1", newUsersPoints).count()</p> <p>but since count() is limited only to 1000 it won't be very useful in my case. Do you have any ideas on how to implement this?</p> <p>I have two</p> <p>First:</p> <ol> <li><p>Use sharding counters idea (<a href="http://code.google.com/intl/pl/appengine/articles/sharding_counters.html" rel="noreferrer">http://code.google.com/intl/pl/appengine/articles/sharding_counters.html</a>) Create new "table" that stores how many scores are in some range(from_points, to_points)</p></li> <li><p>Sum up all counters from above table where range.to_points &lt; newUsersPoints</p></li> <li><p>Find how many scores are bigger than scores in range where the new score is db.GqlQuery("SELECT * FROM Score WHERE points > :1 AND points >= :2 AND points &lt; :3", newUsersPoints, range.from_points, range.to_points).count() + sumfrom2</p></li> <li><p>Find range in which new score is in and increment its counter</p></li> <li><p>Split ranges which counter is bigger than 1000 (or 999) so that 3. wouldn't reach the limit</p></li> <li><p>Add new score to scores table</p></li> </ol> <p>Which is quite complicated and error prone. We might increment some range and Timeout before adding the score. (not transactional)</p> <p>Second idea:</p> <p>From time to time (once every day?) sort all scores by points and give them new positions (script might Timeout so we have to do it in chunks)</p> <p>To find out at which place new score is we just do</p> <p>db.GqlQuery("SELECT * FROM Score WHERE points > :1 LIMIT 1", newUsersPoints).get().precalculated_position + 1</p> <p>Any other ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload