x


Error in HighScoreController.js

I get this error in WebPlayer mode:

Assets/My Scripts/HighScoreController.js(19,62): BCE0023: No appropriate version of 'UnityEngine.WWW.EscapeURL' for the argument list '(Object)' was found.

Here is my HighScoreController script:

pragma strict

private var secretKey = "lolverysecretkey"; // Edit this value and make sure it's the same as the one stored on the server

private var addScoreUrl : String = "http://www.bi.........addscore.php?"; //be sure to add a ? to your url

private var highscoreUrl : String ="http://www.bi.........display.php?";

public var hs_post : WWW;

public var hs_get : WWW;

function Start() {

getScores();

}

function postScore(name, score) {

//This connects to a server side php script that will add the name and score to a MySQL DB.

// Supply it with a string representing the players name and the players score.

var hash = Md5Sum("" + name + score + secretKey + ""); 



var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;



// Post the URL to the site and create a download object to get the result.

hs_post = WWW(highscore_url);

yield hs_post; // Wait until the download is done

if(hs_post.error) {

    print("There was an error posting the high score: " + hs_post.error);

}

}

// Get the scores from the MySQL DB to display in a GUIText.

function getScores() {

// gameObject.guiText.text = "Loading Scores";

gameObject.GetComponent(TextMesh).text = "Loading Scores";

hs_get = WWW(highscoreUrl);

yield hs_get;



if(hs_get.error) {

    print("There was an error getting the high score: " + hs_get.error);

} else {

gameObject.GetComponent(TextMesh).text = hs_get.text;

    //gameObject.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.

}

}

static function Md5Sum(strToEncrypt: String)

{

var encoding = System.Text.UTF8Encoding();

var bytes = encoding.GetBytes(strToEncrypt);



// encrypt bytes

var md5 = System.Security.Cryptography.MD5CryptoServiceProvider();

var hashBytes:byte[] = md5.ComputeHash(bytes);



// Convert the encrypted bytes back to a string (base 16)

var hashString = "";



for (var i = 0; i < hashBytes.Length; i++)

{

    hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, "0"[0]);

}



return hashString.PadLeft(32, "0"[0]);

}

After debugging a bit I found that when I remove the method call; WWW.EscapeURL(name) on line containing: var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;

The error then dissapears... however it then would not convert the name field to a URL friendly one making the code broken. can anyone suggest a fix?

I am not good enough to figure one out yet!

thanks guys!

more ▼

asked Mar 05 '12 at 12:12 AM

tsugaru gravatar image

tsugaru
1 1 1

Have a look at this: http://answers.unity3d.com/questions/45183/adding-extra-information-to-server-side-highscores.html and is name in WWW.EscapeURL(name) a string variable?? It doesn't seem to be declared anywhere..

Mar 05 '12 at 01:50 AM merry_christmas

name is a variable passed in by the constructor. It is a string yes.

Mar 05 '12 at 10:59 PM tsugaru

Have you tried replacing name with a string and checking if the error still occurs, because in the error it sounds kinda like the name variable is of type Object? Maybe I'm totally off, but it'd be worth testing ;)

Mar 05 '12 at 11:08 PM merry_christmas
(comments are locked)
10|3000 characters needed characters left

0 answers: sort oldest
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x810
x524

asked: Mar 05 '12 at 12:12 AM

Seen: 406 times

Last Updated: Mar 05 '12 at 11:08 PM