Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 DimitriUK · Jul 12, 2015 at 04:43 PM · c#stringdatabasescoreupload

Adding Score & Level to Database / Dreamlo

Hello, I have a good high score system working which does also upload and download perfectly to and from the database. I now want to show the Level number that the player managed to reach. If they finally get GameOver, it add's their Username, Score and LevelNumber to the Database. So far, Username and Score is working.

I have NO errors in the code and it shows me the level number in game successfully when it loads up the leaderboards and even puts the level number.

The only part that is NOT working is that it doesn't upload the level number to the database and just shows Name and Score. It seems like the entries length is maxed out to two? That's my guess..

alt text

As you can see, I want to add a third column which is called 'Level'. I am very very new to all this database stuff, and only started around a week ago. If you are willing to educate me on this subject, that would be awesome!

 using UnityEngine;
 using System.Collections;
 
 public class HighScores : MonoBehaviour {
 
     const string privateCode = "//SECRET";
     const string publicCode = "//SECRET";
     const string webURL = "http://dreamlo.com/lb/";
 
     public Highscore[] highscoresList;
     static HighScores instance;
     DisplayHighscores highscoresDisplay;
 
     void Awake() {
         instance = this;
         highscoresDisplay = GetComponent<DisplayHighscores> ();
 
     }
 
     public static void AddNewHighscore(string username, int score, int levelLoaded) 
     
     {
         instance.StartCoroutine (instance.UploadNewHighscore (username, score, levelLoaded));
     }
 
     IEnumerator UploadNewHighscore(string username, int score, int levelLoaded)
     
     {
         WWW WWW = new WWW (webURL + privateCode + "/add/" + WWW.EscapeURL (username) + "/" + score + "/" + levelLoaded);
         yield return WWW;
 
         if (string.IsNullOrEmpty (WWW.error)) {
             print ("Upload Successful");
         DownloadHighscores ();
     }
         else {
             print ("Error uploading: " + WWW.error);
         }
     }
 
     public void DownloadHighscores() 
     
     {
         StartCoroutine ("DownloadHighscoresFromDatabase");
     }
 
     IEnumerator DownloadHighscoresFromDatabase()
         
     {
         WWW WWW = new WWW (webURL + publicCode + "/pipe/");
         yield return WWW;
         
         if (string.IsNullOrEmpty (WWW.error)) {
             FormatHighScores (WWW.text);
             highscoresDisplay.OnHighscoresDownloaded(highscoresList);
         }
             else {
             print ("Error uploading: " + WWW.error);
         }
     }
 
     void FormatHighScores(string textStream) {
         string[] entries = textStream.Split (new char[] {'\n'}, System.StringSplitOptions.RemoveEmptyEntries);
         highscoresList = new Highscore[entries.Length];
 
         for (int i = 0; i <entries.Length; i ++) {
             string[] entryInfo = entries[i].Split(new char[] {'|'});
             string username = entryInfo[0];
             int score = int.Parse(entryInfo[1]);
             int levelLoaded = int.Parse(entryInfo[2]);
             highscoresList[i] = new Highscore(username,score, levelLoaded);
             print (highscoresList[i].username + ": " + highscoresList[i].score + ": " + highscoresList[i].levelLoaded);
         }
     }
 }
 
 public struct Highscore {
 
     public string username;
     public int score;
     public int levelLoaded;
 
 
     public Highscore(string _username, int _score, int _levelLoaded) {
 
             username = _username;
             score = _score;
             levelLoaded = _levelLoaded;
 
     }
 
 }
 


score.png (5.6 kB)
Comment
Add comment · Show 2
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 carmine · Dec 12, 2015 at 06:42 PM 0
Share

@DimitriU$$anonymous$$ Did you figure this out? I had no idea people were posting this stuff to Unity Answers ins$$anonymous$$d of contacting me directly :(

avatar image okkal11 · Mar 31, 2016 at 07:03 AM 0
Share

Same issue, im trying to upload 2 strings and one int, but (entryInfo[2]); returns '0' even though it´s a string.

Did you solve it?

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by TX Manager · Feb 25, 2016 at 03:42 PM

You can manully editing it by making a UI prefab or void OnGUI () on the script it self then get one Text UI prefab and Instantiate it on the right place on the canves then decleere String[] and set it to add Elemenates by every time the data base get a new "High Score" (do this by your own script knowledge). Assigne this string to the Application that the player managed to get to it. like this "String Name" = Application.loadedLevel (don't forget that Application.loadedLevel is class int). then assigen it to the text "Text Name".text = "String Name" (don't forget that this "String Name" is the string[] Elemenete) Then you can Instantiate this text on the canves on it's right transform. Set this transform to chanage every time there's a text already Instantiated note :(I don't know how to assigen String[] to Text.text) :( try it, it may work :)

Comment
Add comment · Show 2 · 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 okkal11 · Mar 31, 2016 at 07:03 AM 0
Share

This has nothing to do with the question?

avatar image TX Manager · Apr 02, 2016 at 07:22 PM 0
Share

I think that he want to make the new high score appear in the list. plz Explian more, I may help

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

24 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Downsize/compress image on upload to Firebase? 0 Answers

System.DateTime truncate Milliseconds 1 Answer

imeCompositionmode 0 Answers


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