Highscores - GameObject error

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

var addScoreUrl="http://viktor.x10.mx/addscore.php?"; //be sure to add a ? to your url
var highscoreUrl="http://viktor.x10.mx/display.php";    

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=Md5.Md5Sum(name + score + secretKey); 

    var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash; //this line adds the score and name to the add url
        
    // 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);
    }
}

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.data; // this is a GUIText that will display the scores in game.
    }


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

Ok so I followed the steps that were available with server side highscores. unifycommunity.com

But I’m a little confused with the last part (step 3). So I copied the HSController script into the scene, and attached it to the gameObject. But after that I’m not really sure what to do. In the scene it states that there is no 'GUIText" attached to the “player” game object, but a script is trying to access it. Well I tried attaching a GUIText but same problem occured.

Btw I just wanted to know where do I make this change. In all my scripts in the game I used playerScore instead of score. Won’t I have to change it so they match?

Sorry for all the questions. Having a hard time understanding this stuff.

Create a GUIText gameobject or an empty gameobject with a GUIText component and attach your script to that, not to your player.

Whether or not you have a variable called score, playerScore or even fishBucket doesn’t matter.

You add a score to the database by calling postScore() and it takes the parameters name and score. Name being a string with the name of the player and score being the numerical score. postScore() does not care with what arguments you call it as long as you do so with 2 arguments matching the type it requires.

You could write:

postScore('asfagdgsd', 923859)

and it would work, or you could write:

var playerScore = 25725;
var playerName = 'Thor';
postScore(playerName, playerScore)

and it would also work. The name of the parameters doesn’t matter, only the the number of parameters and their type.

okay but what if I’m using GUI.Label for my score instead of GUI.Text?

Well, then you change the references to GUI.Text in the script to GUI.Label, I guess.

Why do I get the feeling you’re trying to accomplish something way above your ability? If you’re having trouble replacing simple variables or game objects and understanding arguments and parameters then perhaps an introduction to programming would be more useful than trying to post highscores to a database.

Alright well I’ll try messing with it and hopefully I’ll get it working.

It might be beyond my level but not sure. I’ve practically completed my first real project which I am pretty proud of.
This will be my last finishing touch.

The thing I did not understand was the script is asking for a GUI.Text to be used. Well, I am using a GUI.Label and I cannot create that into a gameObject. The GUI is defined in one of my main player scripts. So, that means I cannot attach the HSController script that is provided in the example. Could you possible create an empty game object, and create a script specifically for the GUI.Label, and use static var (I believe that is what its called)?

By the way, I really appreciate your help. Thanks.

I tried manually putting in the scores in the chart in phpMyAdmin and it came out in the url. But still not sure how to test it from the game to the url… Can anyone help?

edit - function getScores() works
It appeared on the scene as soon as the scene began.
But still not sure how to send my score to the url… Once again, I am not using GUI.Text to represent my scores.

edit 2 -

var playerScore = playerScript.playerScore;
function postScore(name, playerScore) {
    //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 + playerScore + secretKey); 

    var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + playerScore + "&hash=" + hash; //this line adds the score and name to the add url
        
    // 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);
    }
}

Here is the function I have been working on… This sends my score to the url. I changed score to playerScore and identified it by stating where its from. Btw should I say

var playerScore = playerScript.playerScore.ToString()
instead?
Because it says I have to supply the function with a string of the player's name and score.

edit 3 - I tried just stating what the score and name was by just writing var name = “Hello” and var score = 100, but still nothing came out on the other end…

Anyone?