【发布时间】:2017-09-05 23:27:28
【问题描述】:
我正在将一些统一代码实现到我的学校项目中,以添加服务器端的高分。 http://wiki.unity3d.com/index.php?title=Server_Side_Highscores
但是我的浏览器返回此错误 - SyntaxError:意外的标识符“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。你用的是什么浏览器? -
我已经尝试过 Safari 和 Chrome,但它们给了我同样的错误。
-
只有 Firefox 在使用
function定义的函数中支持yield。 ES6 需要function*。
标签: javascript generator yield