0
我正在實施一些代碼從統一到我的學校項目,以添加服務器端高分。 http://wiki.unity3d.com/index.php?title=Server_Side_Highscores意外的標識符'hs_post'
但是我的瀏覽器將返回此錯誤 - 語法錯誤:意外的標識 'hs_post'
我的項目 https://oege.ie.hva.nl/~osengam001/grijptitus/
從我的JS文件
var secretKey = "jonathantitus"; // Edit this value and make sure it's the same as the one stored on the server
var addScoreUrl = "https://oege.ie.hva.nl/~osengam001/grijptitus/php/addscore.php?"; //be sure to add a ? to your url
var highscoreUrl = "https://oege.ie.hva.nl/~osengam001/grijptitus/php/display.php";
function postScore(username, 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 = Md5.Md5Sum(username + titusGevangen + secretKey);
var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(username) + "&score=" + titusGevangen + "&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 {
document.getElementById("beginTekst").innerHTML = hs_get.text; // this is a GUIText that will display the scores in game.
}
}
該錯誤消息意味着解析器不能識別yield。你使用的是什麼瀏覽器? – melpomene
我已經嘗試過Safari和Chrome,他們給我同樣的錯誤。 – Melvin
只有Firefox在使用'function'定義的函數中支持'yield'。 ES6需要['function *'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*)。 – melpomene