01.07.2011

In-Game Scoreloop Account Access

posted by Karsten

It is relatively simple to set up the Scoreloop system within a game using the ScoreloopUI interface that comes with the API download. You just follow the instruction in the docs and voilà, it works, or at least it did for me 😉

However, I wanted to implement a feature in one of my games Rune Escape where I had to check the current in-game currency account, and based on that either show ads or give the user adfreedom within the game. (If this sounds difficult to understand, just download the game, it really isn’t)

I had quite a lot of problems implementing this feature, and I thought that others might benefit from the solution to my problems!

The solution lies in the Scoreloop Core API. What ever you do, do not try and do it by changing the ScoreloopUI code. I tried to do that, but you cannot be certain that the account is correct. The account there is maintaining the integrity, seemingly, for the UI, and not for “hackers” like me. What you need to do is to use the com.scoreloop.client.android.core.controller.UserController object to access the account. This is a little dubious as it is deprecated, but ChallengesController isn’t, and it is performing a similar job accessing challenges instead of the user account, so I assume it is OK, and the documentation doesn’t suggest any new method for accessing the account info.

In order to start the process you should get a UserController and load the user, I do this in the onCreate() of the game’s main Activity:

UserController myUserController = new UserController(this);

myUserController.loadUser();

The argument of UserController accepts a com.scoreloop.client.android.core.controller.UserControllerObserver, so the Activity should implement this interface:

public class GameActivity extends Activity implements UserControllerObserver {

(Alternatively you could do this in a separate class)

loadUser() access the Scoreloop servers and load the user account details. Once it has that it will call public void requestControllerDidReceiveResponse(RequestController cont) and you can now access the information through Session checking which Controller made the request through cont. For  instance this way you can access the balance of the user’s account:

if(cont instanceof UserController) {

Money m = Session.getCurrentSession().getBalance();

float fMoney = m.getAmount().floatValue();

//and do stuff

}

There are quite a few different Controllers available through the Scoreloop Core API and they all work this way, which is great. The only problem is that if you user the game’s Activity class as the Observer for all of them, they all will call requestControllerDidReceiveResponse and that could become a right mess, therefore if you have more than one Controller make sure you check thoroughly what you receive using cont, or alternatively, create Observer objects for each individual Controller – that keeps it clean!

If something goes wrong while the Controller fetch the data from Scoreloop the method public void requestControllerDidFail(RequestController arg0, Exception arg1) is called, and you can do whatever you need to do in that situation. (inform user, what ever…)

 

That’s it, this is all you need to do! I hope this will help someone…

Share

12 Responses to “In-Game Scoreloop Account Access”

  1. Marcelino says:

    Hi!
    Thank you for this great tutorial, it really helped me a lot.
    But I have found some problems and I am wondering if you could help me.

    On the scoreloop settings page, on in-game currency settings, I put 15 as the initial credit value.
    But after I followed your tutorial, the return of this line “float fMoney = m.getAmount().floatValue();” is 1500 instead of 15 as the initial credit value.
    Do you have any pointers you could share on this problem?

    Thank you very very much….

  2. tovida says:

    So I guess if you want to know if the user purchased a certain item or achieved a certain award this would be the best way to do it, right? Also when we are on the topic, do you have any idea how to access the downloaded files after a purchase? The only thing I could come up with is to check if is purchased and if it is to just use it. I have never used in app purchases before so I am not quit sure what will be the best way to do it.

  3. Karsten says:

    This work was done before in-app purchases was implemented, so I’m sorry I don’t know, as I haven’t looked at it yet.

  4. inappforandroid says:

    Google in-app billing is not available in my location. Is it possible to use some Scoreloop variant of in-app billing in such a situation (or does Scoreloop only integrate with an existing google in-app setup).

    The Scoreloop option of user using credit card to pay – I suppose that option will not be acceptable by Google according to their requirement that all payments be using Google methods (Google Checkout and Google in-app billing).

    • Karsten says:

      I am pretty sure that it will work. I have used it for a long time on Google Play. If Play t&c has a clause that you must use their in-app billing then that is new. It wasn’t there when I read the t&c (I did – I am a geek!)

  5. Farhan says:

    I am having an issue on posting the score to Facebook(Social Network)
    after submitting the score. Everything goes fine on demo example. But
    when i have integrated it to my own game. Scores portion submission
    and leaderboard functionality working fime. But when i post score to
    Facebook. Everything happens normally and it shows message “Score
    posted successfully” But in real Score did’nt post on Facbook Wall.
    Please help me what i am missing or how to resolve the issue.
    Thanks in advance 🙂

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment