0

I have my player score located in the gameobject _GM (script = gamemaster.js) like this:

static var currentScore : int = 0;

Now I want this score to be used here: (In the script gameOver.cs located in an other scene)

public void SetScore() {
        var scoreData = new Dictionary<string,string> ();
        scoreData ["score"] = THIS SHOULD BE THE CURRENTSCORE;
        FB.API ("/me/scores", Facebook.HttpMethod.POST, delegate (FBResult result) {
            Debug.Log ("Score submit result: " + result.Text);
        }, scoreData);
    }

So my game can post that data to Facebook.

What is the best way to do this?

1 Answer 1

4

When you have two scripts, especially when they're different langues, what you need to do is pay attention to the script compilation order.

So, what you need to do is this

  • Place your .js file in either Standard Assets, Pro Standard Assets, or Plugins
  • Place your .cs file in any folder except the ones listed above
  • Now, in your .cs file, you can access the score "currentScore" as follows

    scoreData ["score"] = gamemaster.currentScore;
    

Unity Manual - Script compilation order

Sign up to request clarification or add additional context in comments.

4 Comments

I moved my gamemaster.js file to the plugins folder. The problem I have now is that all the references to other scripts (the gamemaster.js is the script that holds the game together) are getting errors. I refer to other scripts like this: ScoreLane7.LaughScorePoint.
Move those scripts into the same folder as gamemaster.js. Problem solved
I cant because those scripts are working with a plugin that has to be compiled befor them. But I rewrote my gamemaster.js script so it no longer needs those scripts. Now I still get this small error: Cannot implicitly convert type int' to string' when I try to post the score to FB.
That's because your score variable is an integer. Change to gamemaster.currentScore.ToString()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.