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?
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.
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.
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!
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.
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 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ā¦