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…
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….
Hi Marcelino
1500 is actually 15 because Scoreloop operates with decimals as well. So think of the floatValue as “Cents”.
Hope that helps.
Oh, I seeeeeee….
OK then, I’ll just add some division to get the real number.
Thanks!
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.
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.
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).
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!)
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 🙂
Personally I never had problems with this. It sounds like a question for the Scoreloop support forum. I have found them to be very helpful in the past.
Thanks Karsten, Some other also have this problem. See link.
Just tell me there, do you need to put some Facebook App id type thing in code for FB sharing or to do some Social Network Changes from web console, or its just straight forward to put the code just. Thanks 🙂
http://stackoverflow.com/questions/15234359/scoreloop-achievements-not-posting-to-facebook-or-twitter-while-saying-that-succ/20011401#20011401
No problem. When I set it up, I followed the guidelines and it just worked. Having said that I believe I only checked it after the game was published (I know, bad, but it wasn’t my prime interest with the game). It could be the game has to be published before it works?
To get a “proper” answer on this I still think the Scoreloop support forum is the way forward. They usually answer fast 😉
Thanks Karsten,
I have posted there as well yesterday. Thanks again 🙂