To have a break from fish AI, this evening decided to set up a highscore board feature as a test case for JSON and online storage for Endure. There are many companies offering this sort of service to game/app developers but I have heard good things about Parse so thought I would try them first.
The best thing is the price... free!
- Requests: 1 million/month
- Pushes: 1 million/month
- Burst Limit: 20/second
There are paid plans available but while in development phase this is perfect.
After creating a new app I created a new class named 'score', using the simple GUI added score and user to the table:
I did try out the Android sample project but without your app being Android as expected there was no way to use the .Jar libraries that Parse provide, but they do offer a great Restful API to POST and GET your data. The website is clean and very clear:
Custom Parse Class
I wrote a very simple Java class and imported Java's own Net and IO libraries, did not take long to get some scores in and out of the service. Connects via HTTPS using an app id and key, so make sure you hide your code before putting it out there.
LibGDX has its own Net library so I also gave this a go as my code looked messy, this too was simple to get working, I have some speed tests to run yet but happy to be able to push and pull data for free and with no real hassle.
I will not go through my code put post the class for you to see, important lines here are:
While looking how others use Parse with Java I saw a lot of complaints about unauthorized errors on data requests, Parse provides many different keys and you have to set and use the right ones depending how you are connecting.
Full Source Code (My Parse Class)
Here I called the class as soon as the game started, a hard coded score is pushed to the 'score' table and then all scores are returned:
Lots of testing left to do with this and of course will need to ask/store the username (@twitter_tag) of the current player. I will use this for the upcoming fishing competition and keep a track of all the fish caught.
Also will need to use a JSON library to properly generate the string that is post (containing username and score) and also parse the results into objects so they can be displayed in game.
Thanks for reading.