Saving playerprefferents on an external database like mysql

Wernand · Lecture 138 · a day ago
Hi guys,

I have successfully a game in the editor to a mysql database by using WCF Services, and it’s working. I can then change the settings volume or difficulty or both, and after clicking the back button, the result is immediately saved to the database. Splendid!! When I test it as a windows application game, all works fine, but when I export it to a WebGL then the program is crashing. I think it has something todo with client side and serverside issue. The game uses some .dll from .net and I think that those are not supported by WebGL. Grrrrr… is there an alternate way for example through ajax because that one is running on the client too. I can’t find much support for the canvas element and ajax. Maybe 1 of you have some good idea’s. It would be nice when I can record some results from a game to a database so it can reflect some scoreboards outside unity.

Cheers,

W Hoefsloot

I do something similar in my WebGL game, I call a PHP script on my webserver to display Leaderboards and to insert/update players in the Leaderboard using JSON. My PHP script returns JSON data from a select statement.

C#

    // Get the scores from the MySQL DB to display in a GUIText.
    // remember to use StartCoroutine when calling this function!
    public IEnumerator GetScores()
    {
        WWW hs_get = new WWW("DisplayLeaderboard.php");
        yield return hs_get;

        if (hs_get.error != null)
        {
                gameObject.GetComponent<Text>().text = "There was an error getting leadboards, please try again later";
        }
        else
        {
            if (hs_get.isDone)
            {
                data = new JSONObject(hs_get.text);
                foreach (var aData in data.list)
                {
                     //Print the returned data
                     Debug.Log(aData);
                }
            }
        }

thx m8 thats what i was looking for.

cheers

No problem!