Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 seanmor96 · Feb 06, 2021 at 12:56 PM · leaderboardhighscores

Problem with adding score to leaderboard

So I have a leaderboard in my game. When a player has finished and their game is over, it should add their score to the leaderboard. If it's a new highscore, their highscore will be changed and updated to the leaderboard and if it isn't a new highscore, the players highscore will remain the same until it is beaten. For some reason when adding a player's name and their highscore, it will only add the name and give the leaderboard entry a score of 0. I have debugged and everything comes up correct so I seem to be referencing everything correctly so I don't know what I'm doing wrong. Here is the adding to leaderboard code below:

 player.coins = player.coins + player.thisGameCoins;
 if(scoreManager.newHighscore == true)
 {
     player.highscore = finalScore;                    
 }

 highscoresManager.AddNewHighscore(menu.userName, player.highscore);
 gameManager.SavePlayerData();

The weird thing is, even if I replace the player.highscore with a hardcoded integer like this:

 highscoresManager.AddNewHighscore(menu.userName, 10);

it will work perfectly and add the value of that integer to the leaderboard so I do not know what I am doing wrong, any help would be appreciated :)

Comment
Add comment · Show 3
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 grimprophecy · Feb 06, 2021 at 09:29 PM 0
Share

Can we take a look at the implementation of AddNewHighscore? As you've tested with a hardcoded value, likely your issue is with writing or reading this data. There doesn't seem to be any logical issue here so without more information it's impossible to tell.

avatar image seanmor96 · Feb 06, 2021 at 09:34 PM 0
Share
     public void AddNewHighscore(string username, float score)
 {
     StartCoroutine(UploadNewHighscore(username, score));
 }

 IEnumerator UploadNewHighscore(string username, float score)
 {
     WWW www = new WWW(webURL + privateCode + "/add/" + 
             WWW.EscapeURL(username) + "/" + score);
     yield return www;

     if (string.IsNullOrEmpty(www.error))
     {
         print("Upload successful!");
     }
     else
     {
         print("Error uploading: " + www.error);
     }
 }
avatar image seanmor96 · Feb 06, 2021 at 09:34 PM 0
Share

I'm currently using the dreamlo leaderboard which is storing data online

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Megaboy238 · Feb 06, 2021 at 09:43 PM

Hard to see from what there is to see, the error is probably with the creation of theplayer.highscore or finalSore variable if we can see that please. Have you tried logging it to the console Debug.Log(finalScore); and player.highscore to make sure it has a value and its type int/float etc

Comment
Add comment · Show 3 · 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 seanmor96 · Feb 06, 2021 at 09:51 PM 0
Share

The final score is the value used whenever the player has beaten their previous highscore. If the player hasn't beaten it, then the highscore will remain the same. Yes I have debugged it and it is giving me the correct value back.

 public float finalScore;
 
 public void Update()
     {
         finalScore = Vector3.Distance(scorePos.transform.position, acid.deathPosition.position);
         finalScore = $$anonymous$$athf.Abs((scorePos.transform.position - acid.deathPosition.position).y / 5);
         score.text = finalScore.ToString("0") + "m";
     }

This is just a variable that displays the final score at the game over menu

avatar image Megaboy238 seanmor96 · Feb 06, 2021 at 10:17 PM 0
Share

only thing i see different is that the documentation uses an int for sore in script and database, you seem to be using float is all the dreamlo scripts using float and the database.

avatar image seanmor96 · Feb 06, 2021 at 11:01 PM 0
Share

Yeah you were right, had to convert finalScore to int whoch worked perfectly. Thank you!

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.

Follow this Question

Answers Answers and Comments

111 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

it is Playerprefs can use in saving highscore and both PC having this can same see data in Highscores? 0 Answers

Making Highscore table with mySql but name doesn't shows? Help please! 0 Answers

Unity - iOS Game Center - *Reliable* Highscore Submission 0 Answers

UnityWebRequest - Going to a URL (without opening) 1 Answer

Retrieving online highscores (following a guide) 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