• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jaysta · Sep 08, 2013 at 10:43 AM · reference

Ambiguous reference 'name': HSController.name, UnityEngine.Object.name.

Hi, I cant figure out how to get the player name from my game to the HSController script.

I have... var name: String = "";

and

To get the players name... name.text = getPlayN.player1;

But i keep getting: Ambiguous reference 'name': HSController.name, UnityEngine.Object.name.

   #pragma strict
     
     private var secretKey: String = ""; // Edit this value and make sure it's the same as the one stored on the server
     var addScoreUrl: String="http://localhost/unity_test/addscore.php?"; //be sure to add a ? to your url
     var highscoreUrl: String="http://localhost/unity_test/display.php";    
     
     var name: String = "";
     var nameText: UILabel;
     var score: int;
     var scoreText: UILabel;
     var loadingText: UILabel;
     var getPlayN : CashCountGemCount;
     
     function Awake(){
         getPlayN = GameObject.FindWithTag("CashNGems").GetComponent(CashCountGemCount);
         score = CashCountGemCount.kills;
     }
     
     function Start() {
         getScores();
     }
     
     function GetPlayersInfo(){
         yield WaitForSeconds(0.2);
             name.text = getPlayN.player1;
         nameText.text = getPlayN.player1;
         scoreText.text = ""+CashCountGemCount.kills;
     }
     
     function postScore(name:String, score:int) {
         //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=md5functions.Md5Sum(name + score + secretKey); 
     
         var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;
             
         // Post the URL to the site and create a download object to get the result.
         var 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() {
         loadingText.text = "Loading Scores";
         var hs_get = WWW(highscoreUrl);
         yield hs_get;
         
         if(hs_get.error) {
             print("There was an error getting the high score: " + hs_get.error);
         } else {
             loadingText.text = hs_get.text; // this is a GUIText that will display the scores in game.
         }
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by legion_44 · Sep 08, 2013 at 10:58 AM

Hi, ambigous reference means, that you want to use some type, that is from two or more references, in this case the 'name' is from UnityEngine.Object.name and from HSController.name, JavaScript(really UnityScript) automaticaly creates a reference from script you create, so solution that is best its to just change the 'name' to something else.

Hope that helps

Paul

Comment
Add comment · Show 14 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jaysta · Sep 08, 2013 at 11:23 AM 0
Share

Thanks Paul, I saw that I might have to change 'name' but could not get my head around it, if I change 'name' then how can I reference 'name' to my players name?

avatar image fafase · Sep 08, 2013 at 11:34 AM 0
Share

If HSController inherits from Object, it has name into it. That is why you are "hiding" the original one. So if it inherits then you can use the HSController object.

avatar image Jaysta · Sep 08, 2013 at 12:02 PM 0
Share

Ah ok I see that I do not need the var name up top.

Then my question would be how do I get player 1 name to 'name'? I added var score and that seems to be no problem with Ambiguous Reference score = CashCountGemCount.kills; .

avatar image Jaysta · Sep 08, 2013 at 01:51 PM 0
Share

O$$anonymous$$ I have changed 'name' to 'pname' and it has removed the error. I know get (when I call postScore):

Failed to call function postScore of class HSController Calling function postScore with 1 parameter but the function requires 2.

What am I doing wrong?

 #pragma strict
 
 private var secret$$anonymous$$ey: String = ""; // Edit this value and make sure it's the same as the one stored on the server
 var addScoreUrl: String="http://localhost/unity_test/addscore.php?"; //be sure to add a ? to your url
 var highscoreUrl: String="http://localhost/unity_test/display.php";    
 
 var pname: String;
 var nameText: UILabel;
 var score: int;
 var scoreText: UILabel;
 var loadingText: UILabel;
 var getPlayN : CashCountGemCount;
 
 function Start() {
     getScores();
     GetPlayersInfo();
 }
 
 function GetPlayersInfo(){
     yield WaitForSeconds(0.2);
     getPlayN = GameObject.FindWithTag("CashNGems").GetComponent(CashCountGemCount);
     score = CashCountGemCount.kills;
     pname = getPlayN.player1;
     nameText.text = getPlayN.player1;
     scoreText.text = ""+CashCountGemCount.kills;
 }
 
 function postScore(pname:String, score:int) {
     //This connects to a server side php script that will add the name and score to a $$anonymous$$ySQL DB.
     // Supply it with a string representing the players name and the players score.
     var hash=md5functions.$$anonymous$$d5Sum(pname + score + secret$$anonymous$$ey); 
 
     var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;
         
     // Post the URL to the site and create a download object to get the result.
     var 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 $$anonymous$$ySQL DB to display in a GUIText.
 function getScores() {
     loadingText.text = "Loading Scores";
     var hs_get = WWW(highscoreUrl);
     yield hs_get;
     
     if(hs_get.error) {
         print("There was an error getting the high score: " + hs_get.error);
     } else {
         loadingText.text = hs_get.text; // this is a GUIText that will display the scores in game.
     }
 }
avatar image flaviusxvii · Sep 08, 2013 at 02:54 PM 0
Share

" Calling function postScore with 1 parameter but the function requires 2."

Isn't this pretty self-explanitory? You're calling postScore and passing only one value.. it's written to accept TWO.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scriptable object saves but what about objects it references? 0 Answers

Can I make reference/assocation to another component as variable? 0 Answers

Change gameobject sprite with button 1 Answer

Copying GameObjects with reference types 1 Answer

Use Of Static Variables 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges