Retrieving Rankings in Scoreloop Core for Android

Hi,

I am writing an Android application which requires me to store scores, achievements, etc. on a server. Since I am short on time, I decided to try Scoreloop (I am also interested in monetizing my application at some point, which Scoreloop should also facilitate without me wasting an eternity writing my own code). Anyhow, I was struggling for a bit with figuring out how to retrieve the ranking of a current user playing my game. I eventually figured out how Scoreloop is setup, and was able to put this code together to do just that:

You can just add this code into your own application, and things should work fine. Just remember to define the ‘user’ variable with whatever you want. For reference, I used:

User user = Session.getCurrentSession().getUser();

Essentially, the way Scoreloop handles its server requests is through an Observer. When you make a call to the observer to retrieve or send something from the server, the RequestControllerObserver kicks in. If the request succeeds, requestControllerDidReceiveResponse(RequestController controller) is fired. You take the local controller object (which is the same as the one which called it outside), and retrieve whatever information you need from it. In my case, I needed the Ranking object. You must call this after requestControllerDidReceiveResponse(RequestController controller) only, otherwise you will get a bunch of ‘null’ values – which no one likes.

I hope that helps. Let me know if you have any questions!

References

Posted in Mini Tuts

Leave a Reply

Your email address will not be published. Required fields are marked *