2017-04-10 9 views
0

サーバーのハイスコアを追加するために、自分の学校プロジェクトにいくつかのコードを実装しています。 http://wiki.unity3d.com/index.php?title=Server_Side_Highscores予期せぬ識別子 'hs_post'

私のブラウザがこのエラーを返しているが - にSyntaxError:予期しない識別子 'hs_post' 私のプロジェクト https://oege.ie.hva.nl/~osengam001/grijptitus/

スニペットの

URL私の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. 
    } 
} 
+0

このエラーメッセージは、パーサーが「yield」を認識しないことを意味します。どのブラウザを使用していますか? – melpomene

+0

私はSafariとChromeの両方を試してみましたが、同じエラーが表示されます。 – Melvin

+1

Firefoxは 'function'を使って定義された関数で' yield'をサポートしています。 ES6には['function *'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*)が必要です。 – melpomene

答えて

1

ありがとうメルポメネ。 Firefoxは関数を使って定義された関数のyieldをサポートしています。 ES6にはfunction*が必要です。