Online Leaderboards

Hullo,

Just putting the finishing touches on my game, but one thing I really want to add is an online leaderboard. Basically, after a player games over, they can add their high score (with a name) onto a leaderboard that display the top ten scores (or something). I can easily take care of the leaderboard stuff, which is pretty simple. Make an array and sort it, or whatever.

My problem is I have really no idea how to do the online component. I have essentially zero experience with online scripting (maybe 20 minutes of HTML) and don’t have any idea where to start for something like this. I’m guessing after the player adds his score, Unity would have to modify some sort of file saved on a server, adding or removing points…or something. I looked around the forums but couldn’t find any helpful info (probably missed a big ā€œLearn Online Leaderboards Here!ā€ thread…), can anyone point me in the right direction to tutorials or info on this subject?

Thanks for any help.

http://www.unifycommunity.com/wiki/index.php?title=Server_Side_Highscores

Has pretty much all you need to know.

Oh boy, I guess I’ll have to learn this mySQL stuff too…fun fun. Thanks for the link!

Yeah, this seems a bit beyond my knowledge at the moment. Do you have any links to an introduction to mySQL databases in general…like how to install and modify them, and so on. I’m currently using 000webhost to test my unity webplayer, to put a bit of context into the situation. I’ve searched around google alot but it’s tough to find some basic introduction information.

If you only need to store a ā€œnameā€ and ā€œscoreā€ what is at that link is just cut/paste.

I’ve got mine working on 000webhost but I need to customise the MySQL tables and iron out a couple of problems.

Ha, I’m stuck on step 1. Installing php admin seems to be tougher than it seems, or I’m just bad at this. Vaguely reminded of myself when I was trying to learn programming.

So basically what I did was follow the link to phpAdmin. Downloaded phpAdmin. Went to the Docs for installation instructions…apparently I need mySQL 5.0 or later. Kinda looked around a bit, and silly as it sounds, have no idea where to get that. Honestly, I’m not even sure what mySQL is. I have essentially no experience with online databases or anything…

Sorry if I’m kinda out of my waters, but it’s tough to find any info on this. For someone like me, what are the basic steps involved to get the Part 1 of the leaderboard wiki tutorial? Download mySQL I’m guessing would be important.

Thanks again for the help.

phpAdmin is in options at 000website and they have the mySQL database too. You don’t need to download/install anything.

Well that’s solves one problem…so I’m a few steps further down the line. Made it all the way to the steps where you put the scripts into Unity itself, and then the problem came. I added the JS script at the bottom of the page into Unity, then followed the link to the Md5 script. However, when I added this into a C# script, I’m getting an error:

BCE0005: Unknown identified: ā€˜MD5’

I named the C# script Md5, and put the function into a static class named Md5…here is my C# script.

using UnityEngine;
using System.Collections;

public class Md5 {
	public  string Md5Sum(string strToEncrypt)
	{
		System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
		byte[] bytes = ue.GetBytes(strToEncrypt);

		// encrypt bytes
		System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
		byte[] hashBytes = md5.ComputeHash(bytes);

		// Convert the encrypted bytes back to a string (base 16)
		string hashString = "";

		for (int i = 0; i < hashBytes.Length; i++)
		{
			hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
		}

		return hashString.PadLeft(32, '0');
	}
}

I use Javascript usually…so I was slightly confused when he that this script is ā€œBest placed in your static-only utility class.ā€ I’m assuming any static class named Md5 will do…but it’s C#, so I dunno. There’s a couple answers to this floating around the forum, but neither of them really worked…tried about every combination of public and static I could do. And the JS version wasn’t playing ball either…

Thanks for bearing with me through this titantic struggle.

Titanic? That sank right? I’ve been kayaking in B.C but don’t remember any icebergs! :stuck_out_tongue:

If you’re using JavaScript for your game, just stick with that for the MD5.
Just cut/paste it into a new file. the name of the file is important, since you’ll use that to access the function.

Best to probably just call it ā€œmd5.jsā€ so the line with the md5sum won’t need editing.

var hash=Md5.Md5Sum(name + score + secretKey);

Edit: If you made the SQL database in 000webhost correctly, you should have the database info to fill in the scripts.

Okay, so I finally figured it out. And you’re partially right: I probably should have stuck with the JS file, but it was doing wonky things (making an error appear in a completely related script).

Apparently JS and C# scripts are compiled at different times, basically meaning that the JS file wouldn’t know that the C# class existed. Ooooo that was tough to find.

So I got all the errors to go away. But don’t worry! I’ll find something to be confused about before this is over.

Basically what I’ve done so far: Made a mySQL database. Did Step 1: Pasted the SQL query into the box, hit go. Skipped the php steps because 000webhost’s ftp manager decided to stop working for a second. Added the two scripts into my Unity game.

Things I THINK I still need to do: Drop both the php scripts somewhere onto my 000webhost. Copy-paste the links from those two URLs into the top of the JS file. Reading Step 2, it seems I have to edit the php scripts to add in the info. I’m guessing that is just replaced the red string texts ā€˜mysql_host’, ā€˜mysql_user’, ā€˜mysql_password’ and ā€˜my_database’ with the info from 000webhost…for example, a8908349_score for the database name (it’s listed on the page).

Okay. Think I might be able to do this. Certainty learning alot today, that’s for sure.

I wasn’t going to confuse you more, with an explanation of why C# version wouldn’t be a good idea! :stuck_out_tongue:

Okay, so I think I have everything setup now. Opened both the urls for the php files, no error messages displayed (blank white screen of course). Time to upload the webplayer and hope it works, I guess.

EDIT: Uploaded the webplayer. To see if it all worked, I called the function postScore(ā€œIronWarriorā€, 8899"); in the Start() function, just before the JS script grabs the scores. Aaaaaaaannnnd it seems to have worked.

I have no idea what this Analytics Code nonsense is, but I’m thinking it’s a problem for another day. Opened it twice, both high scores seem to still be there…I guess it’s working.

Phew, that was tough though. Time for some Apples N’ Cinnamon oatmeal and bed. I’m guessing it’s about 8 or so in England right now, but it’s 11 o’clock pacific time here.

Cheers for all the help callahan, I think I owe you several drinks by now.

I had the same ā€œanalytics.hosting24.comā€ crap too. You need to edit the default.php in the public_html folder.

edit: my bad, forgot about http://members.000webhost.com/analytics.php

I think you have to concentrate on your Game Development, insted of wasting time for saving score on cloud etc… leave this for any Cloud Api’s services
now a days there are a huge variety of this type of backend services… for free… search cloud api’s on google … i am sure you’ll find you solution…
best of luck Bro…

Have a look on Shephertz’s App42 Cloud API,
Now a days It is the Best Solution.

Check out this one : https://github.com/rankpin/rankpin

top/friends/weekly online unity ranking system.

1 Like

This thread is rather old, but since I went through testing several solutions, I can list my findings:

  • SOOMLA - very focused features. I ended up using their social leaderboard. Integration was really quick.
  • GameSparks, Playlab - tons of features, serious learning curve, a bit overkill, expensive if you hit scale
  • Gamedonia - very similar to GameSparks, more reasonably priced
  • Heroic Labs - the new kid on the block. Looks promising too.
1 Like

Look at this tutorial:

You will get the scripts / tutorial-package here:
http://mole.bplaced.net/?page_id=32

It is very easy with this help and completly free…