I followed the tutorial on the wiki and it worked great. As a webplayer but I switched it over to Android and get this error operator + cannot be used with a left hand side of type ‘object’ and a right hand side of type ‘object’. Any help will be appriciated.
Sorry but if anyone else has this problem just change your postscore(name,score) to postscore(name:String,score:int)
You should get used to put #pragma strict in every file if you ever intend to go mobile. saves you lot of time by removing the stuff that will not work on mobile while forcing you to write clean code instead of “good faith” code
Thanks for that info!!
Hi!
I’m having the same problem here. The javascript code from Server Side Highscores is below:
http://wiki.unity3d.com/index.php?title=Server_Side_Highscores
Works with PC, Mac, Linux Standalone, but when I switch to Android it shows all these errors. The same problems show up also if I add the #pragma strict to this as Dreamora suggested.
So can anyone help me solve these errors?
After I change the postScore(name,score) to postScore(name:String,score:int) as BeforeTheLight corrected I still get this error:
Assets/HSController.js(29,5): BCE0005: Unknown identifier: ‘hs_get’.
Assets/HSController.js(30,11): BCE0005: Unknown identifier: ‘hs_get’.
Assets/HSController.js(32,8): BCE0005: Unknown identifier: ‘hs_get’.
Assets/HSController.js(33,63): BCE0005: Unknown identifier: ‘hs_get’.
Assets/HSController.js(35,35): BCE0005: Unknown identifier: ‘hs_get’.
…
private var secretKey="mySecretKey"; // Edit this value and make sure it's the same as the one stored on the server
var addScoreUrl="http://localhost/unity_test/addscore.php?"; //be sure to add a ? to your url
var highscoreUrl="http://localhost/unity_test/display.php";
function Start() {
getScores();
}
function postScore(name:String,score:int) {
//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=Md5.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";
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.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.
}
}
Got it fixed. If anyone else is wondering then in addition to change your postScore(name,score) to postScore(name:String,score:int) just add:
var hs_post : WWW;
var hs_get : WWW;
Thx. I was looking how to fix that.